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

Sean Ross sross at common-lisp.net
Wed Dec 8 10:02:29 UTC 2004


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

Modified Files:
	ChangeLog cl-l10n.asd locale.lisp package.lisp printers.lisp 
	tests.lisp 
Added Files:
	parse-number.lisp parsers.lisp 
Log Message:
Changelog 2004-12-08
Date: Wed Dec  8 11:02:23 2004
Author: sross





Index: cl-l10n/ChangeLog
diff -u cl-l10n/ChangeLog:1.4 cl-l10n/ChangeLog:1.5
--- cl-l10n/ChangeLog:1.4	Tue Dec  7 10:23:29 2004
+++ cl-l10n/ChangeLog	Wed Dec  8 11:02:23 2004
@@ -1,6 +1,15 @@
+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)
+	and ~n(numeric), all other directives are unchanged.
+	* printers.lisp: Use locale-t-fmt if locale-t-fmt-ampm is an 
+	empty string.
+	* locale.lisp: Added support for ECL.
+	* parse-number.lisp, parsers.lisp: Added a basic number parser.
+	
 2004-12-07 Sean Ross <sross at common-lisp.net>
 	* utils.lisp: Patch for flonum-to-digits from Raymond Toy 
-	on cmucl-help (06 Dec 2004, Strange error).
+	on cmucl-help (06 Dec 2004, Subject: Strange error).
 
 2004-12-01 Sean Ross <sross at common-lisp.net>
 	Version 0.1 Release


Index: cl-l10n/cl-l10n.asd
diff -u cl-l10n/cl-l10n.asd:1.4 cl-l10n/cl-l10n.asd:1.5
--- cl-l10n/cl-l10n.asd:1.4	Tue Dec  7 10:23:29 2004
+++ cl-l10n/cl-l10n.asd	Wed Dec  8 11:02:23 2004
@@ -11,16 +11,18 @@
   :name "CL-L10N"
   :author "Sean Ross <sdr at jhb.ucs.co.za>"
   :maintainer "Sean Ross <sdr at jhb.ucs.co.za>"
-  :version "0.1.1"
+  :version "0.1.7"
   :description "Portable CL Locale Support"
   :long-description "Portable CL Package to support localization"
   :licence "MIT"
   :components ((:file "package")
+               (:file "parse-number" :depends-on ("package"))
                (:file "utils" :depends-on ("package"))
                (:file "locale" :depends-on ("utils"))
                (:file "printers" :depends-on ("locale"))
+               (:file "parsers" :depends-on ("printers" "parse-number"))
                (:file "i18n" :depends-on ("printers"))
-               (:file "load-locale" :depends-on ("printers")))
+               (:file "load-locale" :depends-on ("locale")))
   :depends-on (:cl-ppcre))
 
 (defmethod perform :after ((o load-op) (c (eql (find-system :cl-l10n))))


Index: cl-l10n/locale.lisp
diff -u cl-l10n/locale.lisp:1.4 cl-l10n/locale.lisp:1.5
--- cl-l10n/locale.lisp:1.4	Wed Dec  1 12:48:40 2004
+++ cl-l10n/locale.lisp	Wed Dec  8 11:02:23 2004
@@ -5,6 +5,7 @@
 ;;  What to do with LC_CTYPE, LC_COLLATE
 ;;  Test on windows.
 ;;  Parsers?
+;;  locale aliases
 
 (in-package :cl-l10n )
 
@@ -82,7 +83,8 @@
   #+sbcl (sb-ext:posix-getenv word)
   #+lispworks (hcl:getenv word)
   #+cmu (cdr (assoc (intern word :keyword) ext:*environment-list*))
-  #+clisp (ext:getenv word))
+  #+clisp (ext:getenv word)
+  #+ecl (si:getenv word))
 
 
 ;; Getters


Index: cl-l10n/package.lisp
diff -u cl-l10n/package.lisp:1.2 cl-l10n/package.lisp:1.3
--- cl-l10n/package.lisp:1.2	Wed Dec  1 12:48:40 2004
+++ cl-l10n/package.lisp	Wed Dec  8 11:02:23 2004
@@ -4,10 +4,11 @@
 
 (defpackage #:cl-l10n 
   (:use #:cl #:cl-ppcre)
+  (:shadow cl:format)
   (:export #:locale-name #:category-name #:locale #:category #:locale-error
            #:get-category #:get-cat-val #:locale-value #:load-all-locales
            #:*locale* #:*locale-path* #:*locales*
            #:format-number #:print-number #:format-money #:print-money
            #:format-time #:print-time #:add-resources #:bundle 
-           #:add-resource #:gettext))
+           #:add-resource #:gettext #:parse-number))
            


Index: cl-l10n/printers.lisp
diff -u cl-l10n/printers.lisp:1.4 cl-l10n/printers.lisp:1.5
--- cl-l10n/printers.lisp:1.4	Wed Dec  1 12:48:40 2004
+++ cl-l10n/printers.lisp	Wed Dec  8 11:02:23 2004
@@ -126,7 +126,9 @@
   (cond ((and show-time show-date)
          (locale-d-t-fmt locale))
         ((and (not show-date) (not show-time))
-         (locale-t-fmt-ampm locale))
+         (if (string= "" (locale-t-fmt-ampm locale))
+             (locale-t-fmt locale)
+             (locale-t-fmt-ampm locale)))
         (show-time (locale-t-fmt locale))
         (show-date (locale-d-fmt locale))))
 
@@ -356,4 +358,36 @@
     (format-time stream ut show-date show-time locale fmt)
     ut))
       
+
+;; Format
+
+(defun format (stream fmt-string &rest args)
+  (apply #'cl:format stream (parse-fmt-string fmt-string) args))
+
+(defun parse-fmt-string (string)
+  (with-output-to-string (fmt-string)
+    (loop for char across string 
+          with tilde = nil do
+         (case char
+           ((#\@ #\v #\, #\:) (princ char fmt-string))
+           (#\~ (princ char fmt-string)
+                (if tilde 
+                    (setf tilde nil)
+                    (setf tilde t)))
+           (t (if tilde
+                  (progn (setf tilde nil) (princ (get-replacement char) fmt-string))
+                  (princ char fmt-string)))))))
+
+(defvar *directive-replacements*
+  '((#\M . "/cl-l10n:format-money/")
+    (#\U . "/cl-l10n:format-time/")
+    (#\N . "/cl-l10n:format-number/")))
+
+(defun get-replacement (char)
+  (or (cdr (assoc (char-upcase char) *directive-replacements*))
+      char))
+  
+
+
+
 ;; EOF


Index: cl-l10n/tests.lisp
diff -u cl-l10n/tests.lisp:1.1 cl-l10n/tests.lisp:1.2
--- cl-l10n/tests.lisp:1.1	Wed Dec  1 12:52:35 2004
+++ cl-l10n/tests.lisp	Wed Dec  8 11:02:23 2004
@@ -1,6 +1,7 @@
 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;; See the file LICENCE for licence information.
 (defpackage :cl-l10n-tests
+  (:shadowing-import-from :cl-l10n format)
   (:use :cl :regression-test :cl-l10n))
 
 (in-package :cl-l10n-tests)
@@ -132,5 +133,28 @@
     (gettext "howareyou" *my-bundle* "af_ZA")
   "Hoe lyk it")
 
-  
+;; format
+(deftest format.1
+    (format nil "~v:@U" "en_ZA" 3091103120)
+  "Sun 14 Dec 1997 17:45:20 +0200")
+
+(deftest format.2
+    (format nil "~v:n" "en_ZA" 1000)
+  "1,000")
+
+(deftest format.3
+    (format nil "~v:@m" "sv_SE" 1000)
+  "1000,00 SEK")
+
+
+;; parse-number
+(deftest parse-number.1
+    (parse-number (format nil "~vn" "af_ZA" -1001231.5) "af_ZA")
+  -1001231.5)
+
+(deftest parse-number.2
+    (parse-number (format nil "~v@:n" "en_ZA" -1001231.5) "en_ZA")
+  -1001231.5)
+
+
 ;; EOF




More information about the Cl-l10n-cvs mailing list