]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxNumberFormatter class helping to deal with thousands separators.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 19 Jan 2011 10:47:40 +0000 (10:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 19 Jan 2011 10:47:40 +0000 (10:47 +0000)
wxNumberFormatter formats and parses numbers with thousands separators.

Add the class itself as well as documentation and the unit test for it.

See #12166.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

33 files changed:
Makefile.in
build/bakefiles/files.bkl
build/msw/makefile.bcc
build/msw/makefile.gcc
build/msw/makefile.vc
build/msw/makefile.wat
build/msw/wx_base.dsp
build/msw/wx_core.dsp
build/msw/wx_vc7_base.vcproj
build/msw/wx_vc7_core.vcproj
build/msw/wx_vc8_base.vcproj
build/msw/wx_vc8_core.vcproj
build/msw/wx_vc9_base.vcproj
build/msw/wx_vc9_core.vcproj
docs/changes.txt
include/wx/numformatter.h [new file with mode: 0644]
interface/wx/numformatter.h [new file with mode: 0644]
interface/wx/string.h
src/common/numformatter.cpp [new file with mode: 0644]
tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/strings/numformatter.cpp [new file with mode: 0644]
tests/test.bkl
tests/test_test.dsp
tests/test_vc7_test.vcproj
tests/test_vc8_test.vcproj
tests/test_vc9_test.vcproj
wxGTK.spec
wxMotif.spec
wxX11.spec

index 3970e2012ef0d743bf02e35bf0d2e47ad8527079..74c5e06f2bbf5282350ee83d4bba45370cbdb4cb 100644 (file)
@@ -403,6 +403,7 @@ ALL_BASE_HEADERS =  \
        wx/msgout.h \
        wx/msgqueue.h \
        wx/mstream.h \
+       wx/numformatter.h \
        wx/object.h \
        wx/platform.h \
        wx/platinfo.h \
@@ -580,6 +581,7 @@ ALL_PORTS_BASE_HEADERS =  \
        wx/msgout.h \
        wx/msgqueue.h \
        wx/mstream.h \
+       wx/numformatter.h \
        wx/object.h \
        wx/platform.h \
        wx/platinfo.h \
@@ -761,6 +763,7 @@ ALL_BASE_SOURCES =  \
        src/common/mimecmn.cpp \
        src/common/module.cpp \
        src/common/mstream.cpp \
+       src/common/numformatter.cpp \
        src/common/object.cpp \
        src/common/platinfo.cpp \
        src/common/powercmn.cpp \
@@ -959,6 +962,7 @@ MONODLL_OBJECTS =  \
        monodll_mimecmn.o \
        monodll_module.o \
        monodll_mstream.o \
+       monodll_numformatter.o \
        monodll_object.o \
        monodll_platinfo.o \
        monodll_powercmn.o \
@@ -1091,6 +1095,7 @@ MONOLIB_OBJECTS =  \
        monolib_mimecmn.o \
        monolib_module.o \
        monolib_mstream.o \
+       monolib_numformatter.o \
        monolib_object.o \
        monolib_platinfo.o \
        monolib_powercmn.o \
@@ -1218,6 +1223,7 @@ BASEDLL_OBJECTS =  \
        basedll_mimecmn.o \
        basedll_module.o \
        basedll_mstream.o \
+       basedll_numformatter.o \
        basedll_object.o \
        basedll_platinfo.o \
        basedll_powercmn.o \
@@ -1328,6 +1334,7 @@ BASELIB_OBJECTS =  \
        baselib_mimecmn.o \
        baselib_module.o \
        baselib_mstream.o \
+       baselib_numformatter.o \
        baselib_object.o \
        baselib_platinfo.o \
        baselib_powercmn.o \
@@ -15393,6 +15400,9 @@ monodll_module.o: $(srcdir)/src/common/module.cpp $(MONODLL_ODEP)
 monodll_mstream.o: $(srcdir)/src/common/mstream.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/mstream.cpp
 
+monodll_numformatter.o: $(srcdir)/src/common/numformatter.cpp $(MONODLL_ODEP)
+       $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/numformatter.cpp
+
 monodll_object.o: $(srcdir)/src/common/object.cpp $(MONODLL_ODEP)
        $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/object.cpp
 
@@ -20670,6 +20680,9 @@ monolib_module.o: $(srcdir)/src/common/module.cpp $(MONOLIB_ODEP)
 monolib_mstream.o: $(srcdir)/src/common/mstream.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/mstream.cpp
 
+monolib_numformatter.o: $(srcdir)/src/common/numformatter.cpp $(MONOLIB_ODEP)
+       $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/numformatter.cpp
+
 monolib_object.o: $(srcdir)/src/common/object.cpp $(MONOLIB_ODEP)
        $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/object.cpp
 
@@ -25947,6 +25960,9 @@ basedll_module.o: $(srcdir)/src/common/module.cpp $(BASEDLL_ODEP)
 basedll_mstream.o: $(srcdir)/src/common/mstream.cpp $(BASEDLL_ODEP)
        $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/mstream.cpp
 
+basedll_numformatter.o: $(srcdir)/src/common/numformatter.cpp $(BASEDLL_ODEP)
+       $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/numformatter.cpp
+
 basedll_object.o: $(srcdir)/src/common/object.cpp $(BASEDLL_ODEP)
        $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/object.cpp
 
@@ -26448,6 +26464,9 @@ baselib_module.o: $(srcdir)/src/common/module.cpp $(BASELIB_ODEP)
 baselib_mstream.o: $(srcdir)/src/common/mstream.cpp $(BASELIB_ODEP)
        $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/mstream.cpp
 
+baselib_numformatter.o: $(srcdir)/src/common/numformatter.cpp $(BASELIB_ODEP)
+       $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/numformatter.cpp
+
 baselib_object.o: $(srcdir)/src/common/object.cpp $(BASELIB_ODEP)
        $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/object.cpp
 
index 29e22458dc7497c484aa70eb41fbcfc92ea883f5..9d59f444d913a62ccf23a853e8d71dafcb8de6ac 100644 (file)
@@ -362,6 +362,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     src/common/mimecmn.cpp
     src/common/module.cpp
     src/common/mstream.cpp
+    src/common/numformatter.cpp
     src/common/object.cpp
     src/common/platinfo.cpp
     src/common/powercmn.cpp
@@ -490,6 +491,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/msgout.h
     wx/msgqueue.h
     wx/mstream.h
+    wx/numformatter.h
     wx/object.h
     wx/platform.h
     wx/platinfo.h
index cc59e314728cc126c828e9fdba18dd4d9a627ad6..ca01770400dc6f56f29df61d1b661c2c1525d928 100644 (file)
@@ -369,6 +369,7 @@ MONODLL_OBJECTS =  \
        $(OBJS)\monodll_mimecmn.obj \\r
        $(OBJS)\monodll_module.obj \\r
        $(OBJS)\monodll_mstream.obj \\r
+       $(OBJS)\monodll_numformatter.obj \
        $(OBJS)\monodll_object.obj \\r
        $(OBJS)\monodll_platinfo.obj \\r
        $(OBJS)\monodll_powercmn.obj \\r
@@ -516,6 +517,7 @@ MONOLIB_OBJECTS =  \
        $(OBJS)\monolib_mimecmn.obj \\r
        $(OBJS)\monolib_module.obj \\r
        $(OBJS)\monolib_mstream.obj \\r
+       $(OBJS)\monolib_numformatter.obj \
        $(OBJS)\monolib_object.obj \\r
        $(OBJS)\monolib_platinfo.obj \\r
        $(OBJS)\monolib_powercmn.obj \\r
@@ -661,6 +663,7 @@ BASEDLL_OBJECTS =  \
        $(OBJS)\basedll_mimecmn.obj \\r
        $(OBJS)\basedll_module.obj \\r
        $(OBJS)\basedll_mstream.obj \\r
+       $(OBJS)\basedll_numformatter.obj \
        $(OBJS)\basedll_object.obj \\r
        $(OBJS)\basedll_platinfo.obj \\r
        $(OBJS)\basedll_powercmn.obj \\r
@@ -790,6 +793,7 @@ BASELIB_OBJECTS =  \
        $(OBJS)\baselib_mimecmn.obj \\r
        $(OBJS)\baselib_module.obj \\r
        $(OBJS)\baselib_mstream.obj \\r
+       $(OBJS)\baselib_numformatter.obj \
        $(OBJS)\baselib_object.obj \\r
        $(OBJS)\baselib_platinfo.obj \\r
        $(OBJS)\baselib_powercmn.obj \\r
@@ -6000,6 +6004,9 @@ $(OBJS)\monodll_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\monodll_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\monodll_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\monodll_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -8322,6 +8329,9 @@ $(OBJS)\monolib_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\monolib_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\monolib_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\monolib_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -10644,6 +10654,9 @@ $(OBJS)\basedll_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\basedll_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\basedll_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\basedll_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -10977,6 +10990,9 @@ $(OBJS)\baselib_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\baselib_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\baselib_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\baselib_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
index fda53b140a2945e371d52216c9f2314fbaf4d87d..f9d1a5467106db7948db82fbd8996d87085b1743 100644 (file)
@@ -355,6 +355,7 @@ MONODLL_OBJECTS =  \
        $(OBJS)\monodll_mimecmn.o \\r
        $(OBJS)\monodll_module.o \\r
        $(OBJS)\monodll_mstream.o \\r
+       $(OBJS)\monodll_numformatter.o \
        $(OBJS)\monodll_object.o \\r
        $(OBJS)\monodll_platinfo.o \\r
        $(OBJS)\monodll_powercmn.o \\r
@@ -503,6 +504,7 @@ MONOLIB_OBJECTS =  \
        $(OBJS)\monolib_mimecmn.o \\r
        $(OBJS)\monolib_module.o \\r
        $(OBJS)\monolib_mstream.o \\r
+       $(OBJS)\monolib_numformatter.o \
        $(OBJS)\monolib_object.o \\r
        $(OBJS)\monolib_platinfo.o \\r
        $(OBJS)\monolib_powercmn.o \\r
@@ -649,6 +651,7 @@ BASEDLL_OBJECTS =  \
        $(OBJS)\basedll_mimecmn.o \\r
        $(OBJS)\basedll_module.o \\r
        $(OBJS)\basedll_mstream.o \\r
+       $(OBJS)\basedll_numformatter.o \
        $(OBJS)\basedll_object.o \\r
        $(OBJS)\basedll_platinfo.o \\r
        $(OBJS)\basedll_powercmn.o \\r
@@ -779,6 +782,7 @@ BASELIB_OBJECTS =  \
        $(OBJS)\baselib_mimecmn.o \\r
        $(OBJS)\baselib_module.o \\r
        $(OBJS)\baselib_mstream.o \\r
+       $(OBJS)\baselib_numformatter.o \
        $(OBJS)\baselib_object.o \\r
        $(OBJS)\baselib_platinfo.o \\r
        $(OBJS)\baselib_powercmn.o \\r
@@ -6150,6 +6154,9 @@ $(OBJS)\monodll_module.o: ../../src/common/module.cpp
 $(OBJS)\monodll_mstream.o: ../../src/common/mstream.cpp\r
        $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\monodll_numformatter.o: ../../src/common/numformatter.cpp
+       $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\monodll_object.o: ../../src/common/object.cpp\r
        $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<\r
 \r
@@ -8472,6 +8479,9 @@ $(OBJS)\monolib_module.o: ../../src/common/module.cpp
 $(OBJS)\monolib_mstream.o: ../../src/common/mstream.cpp\r
        $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\monolib_numformatter.o: ../../src/common/numformatter.cpp
+       $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\monolib_object.o: ../../src/common/object.cpp\r
        $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<\r
 \r
@@ -10794,6 +10804,9 @@ $(OBJS)\basedll_module.o: ../../src/common/module.cpp
 $(OBJS)\basedll_mstream.o: ../../src/common/mstream.cpp\r
        $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\basedll_numformatter.o: ../../src/common/numformatter.cpp
+       $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\basedll_object.o: ../../src/common/object.cpp\r
        $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<\r
 \r
@@ -11127,6 +11140,9 @@ $(OBJS)\baselib_module.o: ../../src/common/module.cpp
 $(OBJS)\baselib_mstream.o: ../../src/common/mstream.cpp\r
        $(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\baselib_numformatter.o: ../../src/common/numformatter.cpp
+       $(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\baselib_object.o: ../../src/common/object.cpp\r
        $(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index c9b78c7298003a9bd78fe131dc63baccf2bf2938..322a1bfe3b61a99c4a1f271bc3e229a77668961f 100644 (file)
@@ -373,6 +373,7 @@ MONODLL_OBJECTS =  \
        $(OBJS)\monodll_mimecmn.obj \\r
        $(OBJS)\monodll_module.obj \\r
        $(OBJS)\monodll_mstream.obj \\r
+       $(OBJS)\monodll_numformatter.obj \
        $(OBJS)\monodll_object.obj \\r
        $(OBJS)\monodll_platinfo.obj \\r
        $(OBJS)\monodll_powercmn.obj \\r
@@ -527,6 +528,7 @@ MONOLIB_OBJECTS =  \
        $(OBJS)\monolib_mimecmn.obj \\r
        $(OBJS)\monolib_module.obj \\r
        $(OBJS)\monolib_mstream.obj \\r
+       $(OBJS)\monolib_numformatter.obj \
        $(OBJS)\monolib_object.obj \\r
        $(OBJS)\monolib_platinfo.obj \\r
        $(OBJS)\monolib_powercmn.obj \\r
@@ -677,6 +679,7 @@ BASEDLL_OBJECTS =  \
        $(OBJS)\basedll_mimecmn.obj \\r
        $(OBJS)\basedll_module.obj \\r
        $(OBJS)\basedll_mstream.obj \\r
+       $(OBJS)\basedll_numformatter.obj \
        $(OBJS)\basedll_object.obj \\r
        $(OBJS)\basedll_platinfo.obj \\r
        $(OBJS)\basedll_powercmn.obj \\r
@@ -813,6 +816,7 @@ BASELIB_OBJECTS =  \
        $(OBJS)\baselib_mimecmn.obj \\r
        $(OBJS)\baselib_module.obj \\r
        $(OBJS)\baselib_mstream.obj \\r
+       $(OBJS)\baselib_numformatter.obj \
        $(OBJS)\baselib_object.obj \\r
        $(OBJS)\baselib_platinfo.obj \\r
        $(OBJS)\baselib_powercmn.obj \\r
@@ -6580,6 +6584,9 @@ $(OBJS)\monodll_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\monodll_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\monodll_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\monodll_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -8902,6 +8909,9 @@ $(OBJS)\monolib_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\monolib_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\monolib_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\monolib_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -11224,6 +11234,9 @@ $(OBJS)\basedll_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\basedll_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\basedll_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\basedll_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
@@ -11557,6 +11570,9 @@ $(OBJS)\baselib_module.obj: ..\..\src\common\module.cpp
 $(OBJS)\baselib_mstream.obj: ..\..\src\common\mstream.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\common\mstream.cpp\r
 \r
+$(OBJS)\baselib_numformatter.obj: ..\..\src\common\numformatter.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\common\numformatter.cpp
+
 $(OBJS)\baselib_object.obj: ..\..\src\common\object.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\common\object.cpp\r
 \r
index e90fcfeb58b385ebaf245e685adc3f42c4be674b..86cd7fdcf92e56d829224c2c79757ef917c47439 100644 (file)
@@ -3755,6 +3755,7 @@ MONODLL_OBJECTS =  &
        $(OBJS)\monodll_mimecmn.obj &\r
        $(OBJS)\monodll_module.obj &\r
        $(OBJS)\monodll_mstream.obj &\r
+       $(OBJS)\monodll_numformatter.obj &
        $(OBJS)\monodll_object.obj &\r
        $(OBJS)\monodll_platinfo.obj &\r
        $(OBJS)\monodll_powercmn.obj &\r
@@ -3901,6 +3902,7 @@ MONOLIB_OBJECTS =  &
        $(OBJS)\monolib_mimecmn.obj &\r
        $(OBJS)\monolib_module.obj &\r
        $(OBJS)\monolib_mstream.obj &\r
+       $(OBJS)\monolib_numformatter.obj &
        $(OBJS)\monolib_object.obj &\r
        $(OBJS)\monolib_platinfo.obj &\r
        $(OBJS)\monolib_powercmn.obj &\r
@@ -4045,6 +4047,7 @@ BASEDLL_OBJECTS =  &
        $(OBJS)\basedll_mimecmn.obj &\r
        $(OBJS)\basedll_module.obj &\r
        $(OBJS)\basedll_mstream.obj &\r
+       $(OBJS)\basedll_numformatter.obj &
        $(OBJS)\basedll_object.obj &\r
        $(OBJS)\basedll_platinfo.obj &\r
        $(OBJS)\basedll_powercmn.obj &\r
@@ -4174,6 +4177,7 @@ BASELIB_OBJECTS =  &
        $(OBJS)\baselib_mimecmn.obj &\r
        $(OBJS)\baselib_module.obj &\r
        $(OBJS)\baselib_mstream.obj &\r
+       $(OBJS)\baselib_numformatter.obj &
        $(OBJS)\baselib_object.obj &\r
        $(OBJS)\baselib_platinfo.obj &\r
        $(OBJS)\baselib_powercmn.obj &\r
@@ -6409,6 +6413,9 @@ $(OBJS)\monodll_module.obj :  .AUTODEPEND ..\..\src\common\module.cpp
 $(OBJS)\monodll_mstream.obj :  .AUTODEPEND ..\..\src\common\mstream.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<\r
 \r
+$(OBJS)\monodll_numformatter.obj :  .AUTODEPEND ..\..\src\common\numformatter.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
+
 $(OBJS)\monodll_object.obj :  .AUTODEPEND ..\..\src\common\object.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<\r
 \r
@@ -8731,6 +8738,9 @@ $(OBJS)\monolib_module.obj :  .AUTODEPEND ..\..\src\common\module.cpp
 $(OBJS)\monolib_mstream.obj :  .AUTODEPEND ..\..\src\common\mstream.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<\r
 \r
+$(OBJS)\monolib_numformatter.obj :  .AUTODEPEND ..\..\src\common\numformatter.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
+
 $(OBJS)\monolib_object.obj :  .AUTODEPEND ..\..\src\common\object.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<\r
 \r
@@ -11053,6 +11063,9 @@ $(OBJS)\basedll_module.obj :  .AUTODEPEND ..\..\src\common\module.cpp
 $(OBJS)\basedll_mstream.obj :  .AUTODEPEND ..\..\src\common\mstream.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<\r
 \r
+$(OBJS)\basedll_numformatter.obj :  .AUTODEPEND ..\..\src\common\numformatter.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<
+
 $(OBJS)\basedll_object.obj :  .AUTODEPEND ..\..\src\common\object.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<\r
 \r
@@ -11386,6 +11399,9 @@ $(OBJS)\baselib_module.obj :  .AUTODEPEND ..\..\src\common\module.cpp
 $(OBJS)\baselib_mstream.obj :  .AUTODEPEND ..\..\src\common\mstream.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<\r
 \r
+$(OBJS)\baselib_numformatter.obj :  .AUTODEPEND ..\..\src\common\numformatter.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<
+
 $(OBJS)\baselib_object.obj :  .AUTODEPEND ..\..\src\common\object.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<\r
 \r
index 07296167504886f4cb27ae31b5a816505f08911a..833d914cd93b3ae8e2558ea438bf7a4a231b8d8a 100644 (file)
@@ -451,6 +451,10 @@ SOURCE=..\..\src\common\mstream.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\common\numformatter.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\src\common\object.cpp\r
 # End Source File\r
 # Begin Source File\r
@@ -1415,6 +1419,10 @@ SOURCE=..\..\include\wx\mstream.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\include\wx\numformatter.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\include\wx\object.h\r
 # End Source File\r
 # Begin Source File\r
@@ -1659,6 +1667,10 @@ SOURCE=..\..\include\wx\xti.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\include\wx\xti2.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\include\wx\xtictor.h\r
 # End Source File\r
 # Begin Source File\r
index e784b748eaaa1144c6c7c091389634a23e4a5c67..233278896eb59dbb82436dd56eafa5b2c681f0e2 100644 (file)
@@ -6561,6 +6561,10 @@ SOURCE=..\..\include\wx\radiobut.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\include\wx\range.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\include\wx\rawbmp.h\r
 # End Source File\r
 # Begin Source File\r
index dc7b035939eb16b695bd49b02fae4a58b5e3c86c..e1d56dfc69499667b3604ae781e9d1cd88c00de9 100644 (file)
                                RelativePath="..\..\src\common\mstream.cpp">\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\src\common\numformatter.cpp">
+                       </File>
+                       <File
                                RelativePath="..\..\src\common\object.cpp">\r
                        </File>\r
                        <File\r
                                RelativePath="..\..\include\wx\mstream.h">\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\numformatter.h">
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\object.h">\r
                        </File>\r
                        <File\r
                                RelativePath="..\..\include\wx\xti.h">\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\xti2.h">
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\xtictor.h">\r
                        </File>\r
                        <File\r
index dc6d9b5ff60feb5cadcec58d81fce6fb4f31494b..1af35ea21e17c30d3c34cb3e3961bc0388b347e4 100644 (file)
                                RelativePath="..\..\include\wx\radiobut.h">\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\range.h">
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\rawbmp.h">\r
                        </File>\r
                        <File\r
index 0c8af84704ed984e21918140561b49bb8b142a0b..0aca6718c7caae0ef2af3bba07b66d27a642cca4 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\src\common\numformatter.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\src\common\object.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\numformatter.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\object.h"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\xti2.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\xtictor.h"\r
                                >\r
                        </File>\r
index 5a922dcc46a2cdc9e70c4f13cefb7b254dab0a45..c84aa41ddcf3507e56780bb9c94bead1c1115c0a 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\range.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\rawbmp.h"\r
                                >\r
                        </File>\r
index 652986914857cdce0bf6e0e1b832a32ee8a03d25..a888a27815c8579a1a8a0abe1c60ae1532d025dc 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\src\common\numformatter.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\src\common\object.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\numformatter.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\object.h"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\xti2.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\xtictor.h"\r
                                >\r
                        </File>\r
index af4b06be9a6609d3612854aa26e7b04700b0da01..d007bd54f5e50137a4e3ffdb5a9ded80642693f7 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\..\include\wx\range.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\include\wx\rawbmp.h"\r
                                >\r
                        </File>\r
index 3f35549ed63916ed918de5c66cc67e7fcceec569..b1efe24315eb35edde419e9e1bc17034821b5046 100644 (file)
@@ -422,6 +422,7 @@ All:
 - Added wxFile::GetLastError() and ClearLastError() (ryazanov).
 - Added negatable command line switches (Armel Asselin).
 - Added wxVersionInfo and various GetLibraryVersionInfo() functions (troelsk).
+- Added wxNumberFormatter for dealing with thousands separators.
 
 Unix:
 
diff --git a/include/wx/numformatter.h b/include/wx/numformatter.h
new file mode 100644 (file)
index 0000000..02bae6d
--- /dev/null
@@ -0,0 +1,69 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        wx/numformatter.h
+// Purpose:     wxNumberFormatter class
+// Author:      Fulvio Senore, Vadim Zeitlin
+// Created:     2010-11-06
+// Copyright:   (c) 2010 wxWidgets team
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_NUMFORMATTER_H_
+#define _WX_NUMFORMATTER_H_
+
+#include "wx/string.h"
+
+// Helper class for formatting numbers with thousands separators which also
+// supports parsing the numbers formatted by it.
+class WXDLLIMPEXP_BASE wxNumberFormatter
+{
+public:
+    // Bit masks for ToString()
+    enum Style
+    {
+        Style_None              = 0x00,
+        Style_WithThousandsSep  = 0x01,
+        Style_NoTrailingZeroes  = 0x02      // Only for floating point numbers
+    };
+
+    // Format a number as a string. By default, the thousands separator is
+    // used, specify Style_None to prevent this. For floating point numbers,
+    // precision can also be specified.
+    static wxString ToString(long val,
+                             int style = Style_WithThousandsSep);
+
+    static wxString ToString(double val,
+                             int precision,
+                             int style = Style_WithThousandsSep);
+
+    // Parse a string representing a number, possibly with thousands separator.
+    //
+    // Return true on success and stores the result in the provided location
+    // which must be a valid non-NULL pointer.
+    static bool FromString(wxString s, long *val);
+    static bool FromString(wxString s, double *val);
+
+
+    // Get the decimal separator for the current locale. It is always defined
+    // and we fall back to returning '.' in case of an error.
+    static wxChar GetDecimalSeparator();
+
+    // Get the thousands separator if grouping of the digits is used by the
+    // current locale. The value returned in sep should be only used if the
+    // function returns true.
+    static bool GetThousandsSeparatorIfUsed(wxChar *sep);
+
+private:
+    // Add the thousands separators to a string representing a number without
+    // the separators. This is used by ToString(Style_WithThousandsSep).
+    static void AddThousandsSeparators(wxString& s);
+
+    // Remove trailing zeroes and, if there is nothing left after it, the
+    // decimal separator itself from a string representing a floating point
+    // number. Also used by ToString().
+    static void RemoveTrailingZeroes(wxString& s);
+
+    // Remove all thousands separators from a string representing a number.
+    static void RemoveThousandsSeparators(wxString& s);
+};
+
+#endif // _WX_NUMFORMATTER_H_
diff --git a/interface/wx/numformatter.h b/interface/wx/numformatter.h
new file mode 100644 (file)
index 0000000..e989692
--- /dev/null
@@ -0,0 +1,126 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        wx/numformatter.h
+// Purpose:     interface to wxNumberFormatter
+// Author:      Fulvio Senore, Vadim Zeitlin
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+    @class wxNumberFormatter
+
+    Helper class for formatting and parsing numbers with thousands separators.
+
+    This class contains only static functions, so users must not create instances
+    but directly call the member functions.
+
+    @since 2.9.2
+
+    @library{wxbase}
+*/
+class wxNumberFormatter
+{
+public:
+    /**
+        Bit masks used with ToString().
+     */
+    enum Style
+    {
+        /**
+            This flag cab be used to indicate absence of any other flags below.
+         */
+        Style_None              = 0x00,
+
+        /**
+            If this flag is given, thousands separators will be inserted in the
+            number string representation as defined by the current locale.
+         */
+        Style_WithThousandsSep  = 0x01,
+
+        /**
+            If this flag is given, trailing zeroes in a floating point number
+            string representation will be omitted.
+
+            If the number is actually integer, the decimal separator will be
+            omitted as well. To give an example, formatting the number @c 1.23
+            with precision 5 will normally yield "1.23000" but with this flag
+            it would return "1.23". And formatting @c 123 with this flag will
+            return just "123" for any precision.
+
+            This flag can't be used with ToString() overload taking the integer
+            value.
+         */
+        Style_NoTrailingZeroes  = 0x02
+    };
+
+    /**
+        Returns string representation of an integer number.
+
+        By default, the string will use thousands separators if appropriate for
+        the current locale. This can be avoided by passing Style_None as @a
+        flags in which case the call to the function has exactly the same
+        effect as <code>wxString::Format("%ld", val)</code>.
+
+        Notice that calling ToString() with a value of type @c int and
+        non-default flags results in ambiguity between this overload and the
+        one below. To resolve it, you need to cast the value to @c long.
+
+        @param val
+            The variable to convert to a string.
+        @param flags
+            Combination of values from the Style enumeration (except for
+            Style_NoTrailingZeroes which can't be used with this overload).
+    */
+    static wxString ToString(long val, int flags = Style_WithThousandsSep);
+
+    /**
+        Returns string representation of a floating point number.
+
+        @param val
+            The variable to convert to a string.
+        @param precision
+            Number of decimals to write in formatted string.
+        @param flags
+            Combination of values from the Style enumeration.
+    */
+    static wxString
+    ToString(double val, int precision, int flags = Style_WithThousandsSep);
+
+
+    /**
+        Parse a string representation of a number possibly including thousands
+        separators.
+
+        These functions parse number representation in the current locale. On
+        success they return @true and store the result at the location pointed
+        to by @a val (which can't be @NULL), otherwise @false is returned.
+
+        @see wxString::ToLong(), wxString::ToDouble()
+     */
+    //@{
+    static bool FromString(wxString s, long *val);
+    static bool FromString(wxString s, double *val);
+    //@}
+
+    /**
+        Get the decimal separator for the current locale.
+
+        Decimal separators is always defined and we fall back to returning '.'
+        in case of an error.
+     */
+    static wxChar GetDecimalSeparator();
+
+    /**
+        Get the thousands separator if grouping of the digits is used by the
+        current locale.
+
+        The value returned in @a sep should be only used if the function
+        returns @true, otherwise no thousands separator should be used at all.
+
+        @param sep
+            Points to the variable receiving the thousands separator character
+            if it is used by the current locale. May be @NULL if only the
+            function return value is needed.
+     */
+    static bool GetThousandsSeparatorIfUsed(wxChar *sep);
+
+};
index 98ed23b86116e9a9a7fec211a7980bbdd3a49653..f6ca6cd0f56da3df49449773ecf133f8ef3d4b31 100644 (file)
@@ -975,8 +975,13 @@ public:
         you are sure that this string contains a floating point number formatted with
         the rules of the locale currently in use (see wxLocale).
 
-        Refer to the docs of the standard function @c strtod() for more details about
-        the supported syntax.
+        Also notice that even this function is locale-specific it does not
+        support strings with thousands separators in them, even if the current
+        locale uses digits grouping. You may use wxNumberFormatter::FromString()
+        to parse such strings.
+
+        Please refer to the documentation of the standard function @c strtod()
+        for more details about the supported syntax.
 
         @see ToCDouble(), ToLong(), ToULong()
     */
@@ -1015,8 +1020,12 @@ public:
         that this string contains an integer number formatted with
         the rules of the locale currently in use (see wxLocale).
 
-        Refer to the docs of the standard function @c strtol() for more details about
-        the supported syntax.
+        As with ToDouble(), this function does not support strings containing
+        thousands separators even if the current locale uses digits grouping.
+        You may use wxNumberFormatter::FromString() to parse such strings.
+
+        Please refer to the documentation of the standard function @c strtol()
+        for more details about the supported syntax.
 
         @see ToCDouble(), ToDouble(), ToULong()
     */
diff --git a/src/common/numformatter.cpp b/src/common/numformatter.cpp
new file mode 100644 (file)
index 0000000..851259c
--- /dev/null
@@ -0,0 +1,190 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        numformatter.cpp
+// Purpose:     wxNumberFormatter
+// Author:      Fulvio Senore, Vadim Zeitlin
+// Created:     2010-11-06
+// Copyright:   (c) 2010 wxWidgets team
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include "wx/numformatter.h"
+#include "wx/intl.h"
+
+// ============================================================================
+// wxNumberFormatter implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// Locale information accessors
+// ----------------------------------------------------------------------------
+
+wxChar wxNumberFormatter::GetDecimalSeparator()
+{
+    // Notice that while using static variable here is not MT-safe, the worst
+    // that can happen is that we redo the initialization if we're called
+    // concurrently from more than one thread so it's not a real problem.
+    static wxChar s_decimalSeparator = 0;
+
+    if ( !s_decimalSeparator )
+    {
+        const wxString
+            s = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
+        if ( s.empty() )
+        {
+            // We really must have something for decimal separator, so fall
+            // back to the C locale default.
+            s_decimalSeparator = '.';
+        }
+        else
+        {
+            // To the best of my knowledge there are no locales like this.
+            wxASSERT_MSG( s.length() == 1,
+                          "Multi-character decimal separator?" );
+
+            s_decimalSeparator = s[0];
+        }
+    }
+
+    return s_decimalSeparator;
+}
+
+bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep)
+{
+    static wxChar s_thousandsSeparator = 0;
+    static bool s_initialized = false;
+
+    if ( !s_initialized )
+    {
+        const wxString
+            s = wxLocale::GetInfo(wxLOCALE_THOUSANDS_SEP, wxLOCALE_CAT_NUMBER);
+        if ( !s.empty() )
+        {
+            wxASSERT_MSG( s.length() == 1,
+                          "Multi-character thousands separator?" );
+
+            s_thousandsSeparator = s[0];
+        }
+        //else: Unlike above it's perfectly fine for the thousands separator to
+        //      be empty if grouping is not used, so just leave it as 0.
+
+        s_initialized = true;
+    }
+
+    if ( !s_thousandsSeparator )
+        return false;
+
+    if ( sep )
+        *sep = s_thousandsSeparator;
+
+    return true;
+}
+
+// ----------------------------------------------------------------------------
+// Conversion to string and helpers
+// ----------------------------------------------------------------------------
+
+wxString wxNumberFormatter::ToString(long val, int style)
+{
+    wxString s = wxString::Format("%ld", val);
+
+    if ( style & Style_WithThousandsSep )
+        AddThousandsSeparators(s);
+
+    wxASSERT_MSG( !(style & Style_NoTrailingZeroes),
+                  "Style_NoTrailingZeroes can't be used with integer values" );
+
+    return s;
+}
+
+wxString wxNumberFormatter::ToString(double val, int precision, int style)
+{
+    const wxString fmt = wxString::Format("%%.%df", precision);
+    wxString s = wxString::Format(fmt, val);
+
+    if ( style & Style_WithThousandsSep )
+        AddThousandsSeparators(s);
+
+    if ( style & Style_NoTrailingZeroes )
+        RemoveTrailingZeroes(s);
+
+    return s;
+}
+
+void wxNumberFormatter::AddThousandsSeparators(wxString& s)
+{
+    wxChar thousandsSep;
+    if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
+        return;
+
+    size_t pos = s.find(GetDecimalSeparator());
+    if ( pos == wxString::npos )
+    {
+        // Start grouping at the end of an integer number.
+        pos = s.length();
+    }
+
+    // We currently group digits by 3 independently of the locale. This is not
+    // the right thing to do and we should use lconv::grouping (under POSIX)
+    // and GetLocaleInfo(LOCALE_SGROUPING) (under MSW) to get information about
+    // the correct grouping to use. This is something that needs to be done at
+    // wxLocale level first and then used here in the future (TODO).
+    const size_t GROUP_LEN = 3;
+
+    while ( pos > GROUP_LEN )
+    {
+        pos -= GROUP_LEN;
+        s.insert(pos, thousandsSep);
+    }
+}
+
+void wxNumberFormatter::RemoveTrailingZeroes(wxString& s)
+{
+    const size_t posDecSep = s.find(GetDecimalSeparator());
+    wxCHECK_RET( posDecSep != wxString::npos, "No decimal separator" );
+    wxCHECK_RET( posDecSep, "Can't start with decimal separator" );
+
+    // Find the last character to keep.
+    size_t posLastNonZero = s.find_last_not_of("0");
+
+    // If it's the decimal separator itself, don't keep it neither.
+    if ( posLastNonZero == posDecSep )
+        posLastNonZero--;
+
+    s.erase(posLastNonZero + 1);
+}
+
+// ----------------------------------------------------------------------------
+// Conversion from strings
+// ----------------------------------------------------------------------------
+
+void wxNumberFormatter::RemoveThousandsSeparators(wxString& s)
+{
+    wxChar thousandsSep;
+    if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
+        return;
+
+    s.Replace(wxString(thousandsSep), wxString());
+}
+
+bool wxNumberFormatter::FromString(wxString s, long *val)
+{
+    RemoveThousandsSeparators(s);
+    return s.ToLong(val);
+}
+
+bool wxNumberFormatter::FromString(wxString s, double *val)
+{
+    RemoveThousandsSeparators(s);
+    return s.ToDouble(val);
+}
index 995b5c84b34b49b49cf77b963f627e0b1007f9a9..53b6e4dcc15bcfa8635d3d6ae48fc2de584f281d 100644 (file)
@@ -100,6 +100,7 @@ TEST_OBJECTS =  \
        test_wxregextest.o \
        test_scopeguardtest.o \
        test_iostream.o \
+       test_numformatter.o \
        test_strings.o \
        test_stdstrings.o \
        test_tokenizer.o \
@@ -550,6 +551,9 @@ test_scopeguardtest.o: $(srcdir)/scopeguard/scopeguardtest.cpp $(TEST_ODEP)
 test_iostream.o: $(srcdir)/strings/iostream.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/iostream.cpp
 
+test_numformatter.o: $(srcdir)/strings/numformatter.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/numformatter.cpp
+
 test_strings.o: $(srcdir)/strings/strings.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/strings.cpp
 
index dea20435379edd73a77fbbb6e7dbbe0ed6a06505..53a429011fad94105babae471f25fd3ca6168609 100644 (file)
@@ -84,6 +84,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_wxregextest.obj \\r
        $(OBJS)\test_scopeguardtest.obj \\r
        $(OBJS)\test_iostream.obj \\r
+       $(OBJS)\test_numformatter.obj \
        $(OBJS)\test_strings.obj \\r
        $(OBJS)\test_stdstrings.obj \\r
        $(OBJS)\test_tokenizer.obj \\r
@@ -593,6 +594,9 @@ $(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
 $(OBJS)\test_iostream.obj: .\strings\iostream.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp\r
 \r
+$(OBJS)\test_numformatter.obj: .\strings\numformatter.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\numformatter.cpp
+
 $(OBJS)\test_strings.obj: .\strings\strings.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\strings.cpp\r
 \r
index 9c4aa0e01b9ed2dc65537ea803e6e0685b4af1b0..505525af1485479085140644eea1af3a161a9384 100644 (file)
@@ -76,6 +76,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_wxregextest.o \\r
        $(OBJS)\test_scopeguardtest.o \\r
        $(OBJS)\test_iostream.o \\r
+       $(OBJS)\test_numformatter.o \
        $(OBJS)\test_strings.o \\r
        $(OBJS)\test_stdstrings.o \\r
        $(OBJS)\test_tokenizer.o \\r
@@ -574,6 +575,9 @@ $(OBJS)\test_scopeguardtest.o: ./scopeguard/scopeguardtest.cpp
 $(OBJS)\test_iostream.o: ./strings/iostream.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_numformatter.o: ./strings/numformatter.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_strings.o: ./strings/strings.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index 88280b900aaf6276a3e59d09dc45818352452540..233b854b2f1caf3401032602e353cd7fdceba436 100644 (file)
@@ -78,6 +78,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_wxregextest.obj \\r
        $(OBJS)\test_scopeguardtest.obj \\r
        $(OBJS)\test_iostream.obj \\r
+       $(OBJS)\test_numformatter.obj \
        $(OBJS)\test_strings.obj \\r
        $(OBJS)\test_stdstrings.obj \\r
        $(OBJS)\test_tokenizer.obj \\r
@@ -719,6 +720,9 @@ $(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
 $(OBJS)\test_iostream.obj: .\strings\iostream.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp\r
 \r
+$(OBJS)\test_numformatter.obj: .\strings\numformatter.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\numformatter.cpp
+
 $(OBJS)\test_strings.obj: .\strings\strings.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\strings.cpp\r
 \r
index 90dff37c9ae8baaf893c7a582428debe9a859c9b..e35199ad196d6f16c2a1c676728a65f63bd43f72 100644 (file)
@@ -319,6 +319,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_wxregextest.obj &\r
        $(OBJS)\test_scopeguardtest.obj &\r
        $(OBJS)\test_iostream.obj &\r
+       $(OBJS)\test_numformatter.obj &
        $(OBJS)\test_strings.obj &\r
        $(OBJS)\test_stdstrings.obj &\r
        $(OBJS)\test_tokenizer.obj &\r
@@ -632,6 +633,9 @@ $(OBJS)\test_scopeguardtest.obj :  .AUTODEPEND .\scopeguard\scopeguardtest.cpp
 $(OBJS)\test_iostream.obj :  .AUTODEPEND .\strings\iostream.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_numformatter.obj :  .AUTODEPEND .\strings\numformatter.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_strings.obj :  .AUTODEPEND .\strings\strings.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
diff --git a/tests/strings/numformatter.cpp b/tests/strings/numformatter.cpp
new file mode 100644 (file)
index 0000000..30784dd
--- /dev/null
@@ -0,0 +1,239 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/strings/numformat.cpp
+// Purpose:     wxNumberFormatter unit test
+// Author:      Vadim Zeitlin
+// Created:     2011-01-15
+// RCS-ID:      $Id$
+// Copyright:   (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include "wx/numformatter.h"
+#include "wx/intl.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class NumFormatterTestCase : public CppUnit::TestCase
+{
+public:
+    NumFormatterTestCase()
+    {
+        // We need to use a locale with known decimal point and which uses the
+        // thousands separator for the tests to make sense.
+        wxLanguage lang;
+        if ( wxLocale::IsAvailable(wxLANGUAGE_ENGLISH_US) )
+            lang = wxLANGUAGE_ENGLISH_US;
+        else if ( wxLocale::IsAvailable(wxLANGUAGE_ENGLISH_UK) )
+            lang = wxLANGUAGE_ENGLISH_UK;
+        else
+        {
+            m_locale = NULL;
+            return;
+        }
+
+        m_locale = new wxLocale(lang, wxLOCALE_DONT_LOAD_DEFAULT);
+    }
+
+    virtual ~NumFormatterTestCase()
+    {
+        delete m_locale;
+    }
+
+private:
+    CPPUNIT_TEST_SUITE( NumFormatterTestCase );
+        CPPUNIT_TEST( LongToString );
+        CPPUNIT_TEST( DoubleToString );
+        CPPUNIT_TEST( NoTrailingZeroes );
+        CPPUNIT_TEST( LongFromString );
+        CPPUNIT_TEST( DoubleFromString );
+    CPPUNIT_TEST_SUITE_END();
+
+    void LongToString();
+    void DoubleToString();
+    void NoTrailingZeroes();
+    void LongFromString();
+    void DoubleFromString();
+
+    wxLocale *m_locale;
+
+    wxDECLARE_NO_COPY_CLASS(NumFormatterTestCase);
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( NumFormatterTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( NumFormatterTestCase, "NumFormatterTestCase" );
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+void NumFormatterTestCase::LongToString()
+{
+    if ( !m_locale )
+        return;
+
+    CPPUNIT_ASSERT_EQUAL(          "1", wxNumberFormatter::ToString(         1));
+    CPPUNIT_ASSERT_EQUAL(         "12", wxNumberFormatter::ToString(        12));
+    CPPUNIT_ASSERT_EQUAL(        "123", wxNumberFormatter::ToString(       123));
+    CPPUNIT_ASSERT_EQUAL(      "1,234", wxNumberFormatter::ToString(      1234));
+    CPPUNIT_ASSERT_EQUAL(     "12,345", wxNumberFormatter::ToString(     12345));
+    CPPUNIT_ASSERT_EQUAL(    "123,456", wxNumberFormatter::ToString(    123456));
+    CPPUNIT_ASSERT_EQUAL(  "1,234,567", wxNumberFormatter::ToString(   1234567));
+    CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString(  12345678));
+    CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString( 123456789));
+}
+
+void NumFormatterTestCase::DoubleToString()
+{
+    if ( !m_locale )
+        return;
+
+    CPPUNIT_ASSERT_EQUAL("1.0", wxNumberFormatter::ToString(1., 1));
+    CPPUNIT_ASSERT_EQUAL("0.123456", wxNumberFormatter::ToString(0.123456, 6));
+    CPPUNIT_ASSERT_EQUAL("1.234567", wxNumberFormatter::ToString(1.234567, 6));
+    CPPUNIT_ASSERT_EQUAL("12.34567", wxNumberFormatter::ToString(12.34567, 5));
+    CPPUNIT_ASSERT_EQUAL("123.4567", wxNumberFormatter::ToString(123.4567, 4));
+    CPPUNIT_ASSERT_EQUAL("1,234.56", wxNumberFormatter::ToString(1234.56, 2));
+    CPPUNIT_ASSERT_EQUAL("12,345.6", wxNumberFormatter::ToString(12345.6, 1));
+    CPPUNIT_ASSERT_EQUAL("12,345.6", wxNumberFormatter::ToString(12345.6, 1));
+    CPPUNIT_ASSERT_EQUAL("123,456,789.0",
+                         wxNumberFormatter::ToString(123456789., 1));
+    CPPUNIT_ASSERT_EQUAL("123,456,789.012",
+                         wxNumberFormatter::ToString(123456789.012, 3));
+}
+
+void NumFormatterTestCase::NoTrailingZeroes()
+{
+    WX_ASSERT_FAILS_WITH_ASSERT
+    (
+        wxNumberFormatter::ToString(123L, wxNumberFormatter::Style_NoTrailingZeroes)
+    );
+
+    if ( !m_locale )
+        return;
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123.000",
+        wxNumberFormatter::ToString(123., 3)
+    );
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123",
+        wxNumberFormatter::ToString(123., 3, wxNumberFormatter::Style_NoTrailingZeroes)
+    );
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123",
+        wxNumberFormatter::ToString(123., 9, wxNumberFormatter::Style_NoTrailingZeroes)
+    );
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123.456",
+        wxNumberFormatter::ToString(123.456, 3, wxNumberFormatter::Style_NoTrailingZeroes)
+    );
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123.456000000",
+        wxNumberFormatter::ToString(123.456, 9)
+    );
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "123.456",
+        wxNumberFormatter::ToString(123.456, 9, wxNumberFormatter::Style_NoTrailingZeroes)
+    );
+}
+
+void NumFormatterTestCase::LongFromString()
+{
+    if ( !m_locale )
+        return;
+
+    WX_ASSERT_FAILS_WITH_ASSERT
+    (
+        wxNumberFormatter::FromString("123", static_cast<long *>(0))
+    );
+
+    long l;
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("", &l) );
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("foo", &l) );
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("1.234", &l) );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123", &l) );
+    CPPUNIT_ASSERT_EQUAL( 123, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1234", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("12,345", &l) );
+    CPPUNIT_ASSERT_EQUAL( 12345, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123,456", &l) );
+    CPPUNIT_ASSERT_EQUAL( 123456, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234,567", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234567, l );
+}
+
+void NumFormatterTestCase::DoubleFromString()
+{
+    if ( !m_locale )
+        return;
+
+    WX_ASSERT_FAILS_WITH_ASSERT
+    (
+        wxNumberFormatter::FromString("123", static_cast<double *>(0))
+    );
+
+    double d;
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("", &d) );
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("bar", &d) );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123", &d) );
+    CPPUNIT_ASSERT_EQUAL( 123., d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123.456789012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 123.456789012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234.56789012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 1234.56789012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("12,345.6789012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 12345.6789012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123,456.789012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 123456.789012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234,567.89012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 1234567.89012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("12,345,678.9012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 12345678.9012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123,456,789.012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 123456789.012, d );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123456789.012", &d) );
+    CPPUNIT_ASSERT_EQUAL( 123456789.012, d );
+}
index 9afe6d54d8ea30063bfa765cdba5101a8695a019..e11e1360547ef4c4b8f917748d15fb888e61db67 100644 (file)
@@ -75,6 +75,7 @@
             regex/wxregextest.cpp
             scopeguard/scopeguardtest.cpp
             strings/iostream.cpp
+            strings/numformatter.cpp
             strings/strings.cpp
             strings/stdstrings.cpp
             strings/tokenizer.cpp
index 57d10245f18aa85e4402c3d556d011e5f59b8598..96ee1ec6b14cbb1831691dc70438bd51d36580fc 100644 (file)
@@ -429,6 +429,10 @@ SOURCE=.\misc\module.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\strings\numformatter.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\interactive\output.cpp\r
 # End Source File\r
 # Begin Source File\r
index 753e3489caa1a3980f87c9867c118f6a54586412..1c0e9d08a6cba092a894d40805755e99b9504fcd 100644 (file)
                                RelativePath=".\misc\module.cpp">\r
                        </File>\r
                        <File\r
+                               RelativePath=".\strings\numformatter.cpp">
+                       </File>
+                       <File
                                RelativePath=".\interactive\output.cpp">\r
                        </File>\r
                        <File\r
index ddbf79007f1fb93a5e850507e11d0903cf311fc4..16622ac1a723505e31c46cadb4d3f1800657ce29 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\strings\numformatter.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\interactive\output.cpp"\r
                                >\r
                        </File>\r
index c35f4cb7aaed015afad1c4faf4329863ad46c902..58ec3cdcbe1fde92be7d130851951316494bb48e 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\strings\numformatter.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\interactive\output.cpp"\r
                                >\r
                        </File>\r
index e6f3076cc9c75b38a5d60c5bacb8f27d5e4db1df..ae6e40083715797624a5db50c973a03be4d68e32 100644 (file)
@@ -270,6 +270,7 @@ wx/mousestate.h
 wx/msgout.h
 wx/msgqueue.h
 wx/mstream.h
+wx/numformatter.h
 wx/object.h
 wx/platform.h
 wx/platinfo.h
index d42149894c19a2943b6365ef3bfb3c0e185a67b5..54bf5c51a47d980881ce4e74dab00f5b9ea73a7b 100644 (file)
@@ -172,6 +172,7 @@ wx/mousestate.h
 wx/msgout.h
 wx/msgqueue.h
 wx/mstream.h
+wx/numformatter.h
 wx/object.h
 wx/platform.h
 wx/platinfo.h
index 36ad6ed3c3955899eeca7bcdf800b66e4ec1e16a..cf642ac112837800d7600aaf0db856e1061facc4 100644 (file)
@@ -196,6 +196,7 @@ wx/mousestate.h
 wx/msgout.h
 wx/msgqueue.h
 wx/mstream.h
+wx/numformatter.h
 wx/object.h
 wx/platform.h
 wx/platinfo.h