[cl-l10n-cvs] CVS update: cl-l10n/ChangeLog cl-l10n/cl-l10n.asd cl-l10n/parse-number.lisp cl-l10n/parsers.lisp cl-l10n/printers.lisp cl-l10n/tests.lisp

Sean Ross sross at common-lisp.net
Fri Dec 17 10:06:46 UTC 2004


Update of /project/cl-l10n/cvsroot/cl-l10n
In directory common-lisp.net:/tmp/cvs-serv19681

Modified Files:
	ChangeLog cl-l10n.asd parse-number.lisp parsers.lisp 
	printers.lisp tests.lisp 
Log Message:
Changelog 2004-12-17
Date: Fri Dec 17 11:06:43 2004
Author: sross

Index: cl-l10n/ChangeLog
diff -u cl-l10n/ChangeLog:1.5 cl-l10n/ChangeLog:1.6
--- cl-l10n/ChangeLog:1.5	Wed Dec  8 11:02:23 2004
+++ cl-l10n/ChangeLog	Fri Dec 17 11:06:43 2004
@@ -1,6 +1,17 @@
+2004-12-17 Sean Ross	<sross at common-lisp.net>
+	* printers.lisp: Fixed incorrect sign when printing 
+	numbers and money.
+	* printers.lisp: The :no-dp arg whas ignored when 
+	printing numbers, fixed.
+	* printers.lisp: Added *float-digits*. Used when printing
+	numbers, when all numbers after the decimal point are zero
+	only *float-digits* zeros will be printed.
+	* printers.lisp: Fixed format to accept a function as the 
+	format control.
+
 2004-12-08 Sean Ross	<sross at common-lisp.net>
 	* printers.lisp: Added format which can be shadow imported
-	to provide 3 new format directive ~u(universal-time), ~m(monetary)
+	to provide 3 new format directives ~u(universal-time), ~m(monetary)
 	and ~n(numeric), all other directives are unchanged.
 	* printers.lisp: Use locale-t-fmt if locale-t-fmt-ampm is an 
 	empty string.


Index: cl-l10n/cl-l10n.asd
diff -u cl-l10n/cl-l10n.asd:1.5 cl-l10n/cl-l10n.asd:1.6
--- cl-l10n/cl-l10n.asd:1.5	Wed Dec  8 11:02:23 2004
+++ cl-l10n/cl-l10n.asd	Fri Dec 17 11:06:43 2004
@@ -11,7 +11,7 @@
   :name "CL-L10N"
   :author "Sean Ross <sdr at jhb.ucs.co.za>"
   :maintainer "Sean Ross <sdr at jhb.ucs.co.za>"
-  :version "0.1.7"
+  :version "0.1.10"
   :description "Portable CL Locale Support"
   :long-description "Portable CL Package to support localization"
   :licence "MIT"


Index: cl-l10n/parse-number.lisp
diff -u cl-l10n/parse-number.lisp:1.1 cl-l10n/parse-number.lisp:1.2
--- cl-l10n/parse-number.lisp:1.1	Wed Dec  8 11:02:23 2004
+++ cl-l10n/parse-number.lisp	Fri Dec 17 11:06:43 2004
@@ -303,15 +303,4 @@
 				      :end end
 				      :radix radix))))))))
 		 
-(defparameter *test-values*
-  '("1" "-1" "1034" "-364" "80/335" "3.5333" "2.4E4" "6.8d3" "#xFF" "#b-1000" "#o-101/75" "13.09s3" "35.66l5" "21.4f2" "#C(1 2)" "#c ( #xF #o-1 ) " "#c(1d1 2s1)" "#16rFF" "#9r10" "#C(#9r44/61 4f4)"))
-
-(defun run-tests ()
-  (format t "~&~16 at A (~16 at A) = ~16A~%~%"
-	  "String value" "READ value" "Parsed value")
-  (dolist (value *test-values*)
-    (format t "~&~16 at A (~16 at A) = ~16A~%"
-	    value
-	    (read-from-string value)
-	    (%parse-number value))))
 


Index: cl-l10n/parsers.lisp
diff -u cl-l10n/parsers.lisp:1.1 cl-l10n/parsers.lisp:1.2
--- cl-l10n/parsers.lisp:1.1	Wed Dec  8 11:02:23 2004
+++ cl-l10n/parsers.lisp	Fri Dec 17 11:06:43 2004
@@ -19,4 +19,5 @@
       (t num))))
 
 
+;; money parser
 ;; EOF


Index: cl-l10n/printers.lisp
diff -u cl-l10n/printers.lisp:1.5 cl-l10n/printers.lisp:1.6
--- cl-l10n/printers.lisp:1.5	Wed Dec  8 11:02:23 2004
+++ cl-l10n/printers.lisp	Fri Dec 17 11:06:43 2004
@@ -15,9 +15,9 @@
             sign (mapcar #'nreverse (nreverse (group digits grouping))))))
 
 (defun get-sign (arg locale)
-  (if (plusp arg)
-      (locale-positive-sign locale)
-      (locale-negative-sign locale)))
+  (cond ((plusp arg) (locale-positive-sign locale))
+        ((minusp arg) (locale-negative-sign locale))
+        (t "")))
 
 (defun get-point (locale no-point float-part)
   (if (and (string= float-part "0") no-point)
@@ -35,17 +35,29 @@
     (string (locale loc))
     (symbol (locale (string loc)))))
 
+(defvar *float-digits* 2
+  "Used when all values after the decimal point are zero to
+determine the number of zero's to print")
+
 (defun format-number (stream arg no-dp no-ts
                       &optional (locale *locale*))
   (let ((locale (locale-des->locale locale)))
     (multiple-value-bind (int-part float-part) (split-float (abs (float arg)))
       (let* ((sign (get-sign arg locale))
              (point (get-point locale no-dp float-part))
+             (float-part (if (every #'(lambda (x)
+                                        (zerop (or (digit-char-p x) 1)))
+                                    float-part)
+                             (make-string *float-digits*
+                                          :initial-element #\0)
+                             float-part))
              (sep (get-sep locale no-ts))
-             (grouping (locale-grouping locale))
-             (*read-eval* nil))
+             (grouping (locale-grouping locale)))
         (print-int stream sign int-part sep grouping)
-        (unless (and (or* (string= float-part "" "0")) no-dp)
+        (unless (and (every #'(lambda (x)
+                                (zerop (or (digit-char-p x) 1)))
+                            float-part)
+                     no-dp)
           (princ point stream)
           (princ float-part stream))))))
 
@@ -94,7 +106,7 @@
                         (locale-int-curr-symbol locale)
                         (locale-currency-symbol locale)))
                (sym-sep (if (zerop sep-by-space) "" " ")))
-
+          
           (when (or* (= spos 0 1 3))
             (princ (if (zerop spos) "(" sign) stream)
             (when (= 2 sep-by-space)
@@ -361,8 +373,12 @@
 
 ;; Format
 
-(defun format (stream fmt-string &rest args)
-  (apply #'cl:format stream (parse-fmt-string fmt-string) args))
+(defun format (stream fmt-cntrl &rest args)
+  (apply #'cl:format stream
+         (etypecase fmt-cntrl
+           (function fmt-cntrl)
+           (string (parse-fmt-string fmt-cntrl)))
+         args))
 
 (defun parse-fmt-string (string)
   (with-output-to-string (fmt-string)


Index: cl-l10n/tests.lisp
diff -u cl-l10n/tests.lisp:1.2 cl-l10n/tests.lisp:1.3
--- cl-l10n/tests.lisp:1.2	Wed Dec  8 11:02:23 2004
+++ cl-l10n/tests.lisp	Fri Dec 17 11:06:43 2004
@@ -23,11 +23,11 @@
 
 (deftest number.3
     (format nil "~v/cl-l10n:format-number/" "en_ZA" 1000)
-  "1,000.0")
+  "1,000.00")
 
 (deftest number.4
     (format nil "~v/cl-l10n:format-number/" "sv_SE" 1000)
-  "1 000,0")
+  "1 000,00")
 
 (deftest number.5
     (format nil "~v:/cl-l10n:format-number/" "sv_SE" 1000)




More information about the Cl-l10n-cvs mailing list