1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-15 08:10:17 +02:00

format: Add specifier ~h for localized number output.

* doc/ref/misc-modules.texi (Formatted Output): Document ~h.  Recommend
  use of ~h instead of ~:d.

* module/ice-9/format.scm (format): Add support for ~h.

* test-suite/tests/format.test ("~h localized number"): New test prefix.

* test-suite/tests/i18n.test (%american-english-locale-name,
  %american-english-locale): New variables.
  (under-american-english-locale-or-unresolved): New procedure.
  ("format ~h"): New test prefix.
This commit is contained in:
Ludovic Courtès 2012-02-03 16:35:06 +01:00
parent c76fdf69a8
commit afd08fdf87
4 changed files with 109 additions and 7 deletions

View file

@ -1,5 +1,5 @@
;;;; "format.scm" Common LISP text output formatter for SLIB
;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
@ -31,6 +31,7 @@
(define-module (ice-9 format)
#:autoload (ice-9 pretty-print) (pretty-print truncated-print)
#:autoload (ice-9 i18n) (%global-locale number->locale-string)
#:replace (format))
(define format:version "3.0")
@ -272,6 +273,24 @@
((#\D) ; Decimal
(format:out-num-padded modifier (next-arg) params 10)
(anychar-dispatch))
((#\H) ; Localized number
(let* ((num (next-arg))
(locale (case modifier
((colon) (next-arg))
(else %global-locale)))
(argc (length params))
(width (format:par params argc 0 #f "width"))
(decimals (format:par params argc 1 #t "decimals"))
(padchar (integer->char
(format:par params argc 2 format:space-ch
"padchar")))
(str (number->locale-string num decimals
locale)))
(format:out-str (if (and width
(< (string-length str) width))
(string-pad str width padchar)
str)))
(anychar-dispatch))
((#\X) ; Hexadecimal
(format:out-num-padded modifier (next-arg) params 16)
(anychar-dispatch))