summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/samples/numfmt
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/icu-xetex/samples/numfmt')
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/Makefile22
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/capi.c77
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/main.cpp274
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/numfmt.sln21
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/numfmt.vcproj164
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/readme.txt61
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/util.cpp117
-rw-r--r--Build/source/libs/icu-xetex/samples/numfmt/util.h20
8 files changed, 756 insertions, 0 deletions
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/Makefile b/Build/source/libs/icu-xetex/samples/numfmt/Makefile
new file mode 100644
index 00000000000..eca17b21692
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/Makefile
@@ -0,0 +1,22 @@
+# Copyright (c) 2000-2002 IBM, Inc. and others
+# sample code makefile
+
+# Usage:
+# - configure, build, install ICU (make install)
+# - make sure "icu-config" (in the ICU installed bin directory) is on
+# the path
+# - do 'make' in this directory
+
+#### definitions
+# Name of your target
+TARGET=numfmt
+
+# All object files (C or C++)
+OBJECTS=main.o util.o capi.o
+
+#### rules
+# Load in standard makefile definitions
+include ../defs.mk
+
+# the actual rules (this is a simple sample)
+include ../rules.mk
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/capi.c b/Build/source/libs/icu-xetex/samples/numfmt/capi.c
new file mode 100644
index 00000000000..9b8a1117b12
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/capi.c
@@ -0,0 +1,77 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/unum.h"
+#include "unicode/ustring.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+static void uprintf(const UChar* str) {
+ char buf[256];
+ u_austrcpy(buf, str);
+ printf("%s", buf);
+}
+
+void capi() {
+ UNumberFormat *fmt;
+ UErrorCode status = U_ZERO_ERROR;
+ /* The string "987654321.123" as UChars */
+ UChar str[] = { 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33,
+ 0x32, 0x31, 0x30, 0x2E, 0x31, 0x32, 0x33, 0 };
+ UChar buf[256];
+ int32_t needed;
+ double a;
+
+ /* Create a formatter for the US locale */
+ fmt = unum_open(
+ UNUM_DECIMAL, /* style */
+ 0, /* pattern */
+ 0, /* patternLength */
+ "en_US", /* locale */
+ 0, /* parseErr */
+ &status);
+ if (U_FAILURE(status)) {
+ printf("FAIL: unum_open\n");
+ exit(1);
+ }
+
+ /* Use the formatter to parse a number. When using the C API,
+ we have to specify whether we want a double or a long in advance.
+
+ We pass in NULL for the position pointer in order to get the
+ default behavior which is to parse from the start. */
+ a = unum_parseDouble(fmt, str, u_strlen(str), NULL, &status);
+ if (U_FAILURE(status)) {
+ printf("FAIL: unum_parseDouble\n");
+ exit(1);
+ }
+
+ /* Show the result */
+ printf("unum_parseDouble(\"");
+ uprintf(str);
+ printf("\") => %g\n", a);
+
+ /* Use the formatter to format the same number back into a string
+ in the US locale. The return value is the buffer size needed.
+ We're pretty sure we have enough space, but in a production
+ application one would check this value.
+
+ We pass in NULL for the UFieldPosition pointer because we don't
+ care to receive that data. */
+ needed = unum_formatDouble(fmt, a, buf, 256, NULL, &status);
+ if (U_FAILURE(status)) {
+ printf("FAIL: format_parseDouble\n");
+ exit(1);
+ }
+
+ /* Show the result */
+ printf("unum_formatDouble(%g) => \"", a);
+ uprintf(buf);
+ printf("\"\n");
+
+ /* Release the storage used by the formatter */
+ unum_close(fmt);
+}
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/main.cpp b/Build/source/libs/icu-xetex/samples/numfmt/main.cpp
new file mode 100644
index 00000000000..1ebd4948c37
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/main.cpp
@@ -0,0 +1,274 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2004, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/utypes.h"
+#include "unicode/unistr.h"
+#include "unicode/numfmt.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/decimfmt.h"
+#include "unicode/locid.h"
+#include "unicode/uclean.h"
+#include "util.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
+extern "C" void capi();
+void cppapi();
+
+static void
+showCurrencyFormatting(UBool useICU26API);
+
+int main(int argc, char **argv) {
+ printf("%s output is in UTF-8\n", argv[0]);
+
+ printf("C++ API\n");
+ cppapi();
+
+ printf("C API\n");
+ capi();
+
+ showCurrencyFormatting(FALSE);
+ showCurrencyFormatting(TRUE);
+
+ u_cleanup(); // Release any additional storage held by ICU.
+
+ printf("Exiting successfully\n");
+ return 0;
+}
+
+/**
+ * Sample code for the C++ API to NumberFormat.
+ */
+void cppapi() {
+ Locale us("en", "US");
+ UErrorCode status = U_ZERO_ERROR;
+
+ // Create a number formatter for the US locale
+ NumberFormat *fmt = NumberFormat::createInstance(us, status);
+ check(status, "NumberFormat::createInstance");
+
+ // Parse a string. The string uses the digits '0' through '9'
+ // and the decimal separator '.', standard in the US locale
+ UnicodeString str("9876543210.123");
+ Formattable result;
+ fmt->parse(str, result, status);
+ check(status, "NumberFormat::parse");
+
+ printf("NumberFormat::parse(\""); // Display the result
+ uprintf(str);
+ printf("\") => ");
+ uprintf(formattableToString(result));
+ printf("\n");
+
+ // Take the number parsed above, and use the formatter to
+ // format it.
+ str.remove(); // format() will APPEND to this string
+ fmt->format(result, str, status);
+ check(status, "NumberFormat::format");
+
+ printf("NumberFormat::format("); // Display the result
+ uprintf(formattableToString(result));
+ printf(") => \"");
+ uprintf(str);
+ printf("\"\n");
+
+ delete fmt; // Release the storage used by the formatter
+
+}
+
+// currency formatting ----------------------------------------------------- ***
+
+/*
+ * Set a currency on a NumberFormat with pre-ICU 2.6 APIs.
+ * This is a "hack" that will not work properly for all cases because
+ * only ICU 2.6 introduced a more complete framework and data for this.
+ *
+ * @param nf The NumberFormat on which to set the currency; takes effect on
+ * currency-formatting NumberFormat instances.
+ * This must actually be a DecimalFormat instance.
+ * The display style of the output is controlled by nf (its pattern,
+ * usually from the display locale ID used to create this instance)
+ * while the currency symbol and number of decimals are set for
+ * the currency.
+ * @param currency The 3-letter ISO 4217 currency code, NUL-terminated.
+ * @param errorCode ICU error code, must pass U_SUCCESS() on input.
+ */
+static void
+setNumberFormatCurrency_2_4(NumberFormat &nf, const char *currency, UErrorCode &errorCode) {
+ // argument checking
+ if(U_FAILURE(errorCode)) {
+ return;
+ }
+ if(currency==NULL || strlen(currency)!=3) {
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ // check that the formatter is a DecimalFormat instance
+ // necessary because we will cast to the DecimalFormat subclass to set
+ // the currency symbol
+ if(nf.getDynamicClassID()!=DecimalFormat::getStaticClassID()) {
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ // map the currency code to a locale ID
+ // only the currencies in this array are supported
+ // it would be possible to map to a locale ID, instantiate a currency
+ // formatter for that and copy its values, but that would be slower,
+ // and we have to hardcode something here anyway
+ static const struct {
+ // ISO currency ID
+ const char *currency;
+
+ // fractionDigits==minimumFractionDigits==maximumFractionDigits
+ // for these currencies
+ int32_t fractionDigits;
+
+ /*
+ * Set the rounding increment to 0 if it is implied with the number of
+ * fraction digits. Setting an explicit rounding increment makes
+ * number formatting slower.
+ * In other words, set it to something other than 0 only for unusual
+ * cases like "nickel rounding" (0.05) when the increment differs from
+ * 10^(-maximumFractionDigits).
+ */
+ double roundingIncrement;
+
+ // Unicode string with the desired currency display symbol or name
+ UChar symbol[16];
+ } currencyMap[]={
+ { "USD", 2, 0.0, { 0x24, 0 } },
+ { "GBP", 2, 0.0, { 0xa3, 0 } },
+ { "EUR", 2, 0.0, { 0x20ac, 0 } },
+ { "JPY", 0, 0.0, { 0xa5, 0 } }
+ };
+
+ int32_t i;
+
+ for(i=0; i<LENGTHOF(currencyMap); ++i) {
+ if(strcmp(currency, currencyMap[i].currency)==0) {
+ break;
+ }
+ }
+ if(i==LENGTHOF(currencyMap)) {
+ // a more specific error code would be useful in a real application
+ errorCode=U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ // set the currency-related data into the caller's formatter
+
+ nf.setMinimumFractionDigits(currencyMap[i].fractionDigits);
+ nf.setMaximumFractionDigits(currencyMap[i].fractionDigits);
+
+ DecimalFormat &dnf=(DecimalFormat &)nf;
+ dnf.setRoundingIncrement(currencyMap[i].roundingIncrement);
+
+ DecimalFormatSymbols symbols(*dnf.getDecimalFormatSymbols());
+ symbols.setSymbol(DecimalFormatSymbols::kCurrencySymbol, currencyMap[i].symbol);
+ dnf.setDecimalFormatSymbols(symbols); // do not adopt symbols: Jitterbug 2889
+}
+
+/*
+ * Set a currency on a NumberFormat with ICU 2.6 APIs.
+ *
+ * @param nf The NumberFormat on which to set the currency; takes effect on
+ * currency-formatting NumberFormat instances.
+ * The display style of the output is controlled by nf (its pattern,
+ * usually from the display locale ID used to create this instance)
+ * while the currency symbol and number of decimals are set for
+ * the currency.
+ * @param currency The 3-letter ISO 4217 currency code, NUL-terminated.
+ * @param errorCode ICU error code, must pass U_SUCCESS() on input.
+ */
+static void
+setNumberFormatCurrency_2_6(NumberFormat &nf, const char *currency, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) {
+ return;
+ }
+ if(currency==NULL || strlen(currency)!=3) {
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ // invariant-character conversion to UChars (see utypes.h and putil.h)
+ UChar uCurrency[4];
+ u_charsToUChars(currency, uCurrency, 4);
+
+ // set the currency
+ // in ICU 3.0 this API (which was @draft ICU 2.6) gained a UErrorCode& argument
+#if (U_ICU_VERSION_MAJOR_NUM < 3)
+ nf.setCurrency(uCurrency);
+#else
+ nf.setCurrency(uCurrency, errorCode);
+#endif
+}
+
+static const char *const
+sampleLocaleIDs[]={
+ // use locale IDs complete with country code to be sure to
+ // pick up number/currency format patterns
+ "en_US", "en_GB", "de_DE", "ja_JP", "fr_FR", "hi_IN"
+};
+
+static const char *const
+sampleCurrencies[]={
+ "USD", "GBP", "EUR", "JPY"
+};
+
+static void
+showCurrencyFormatting(UBool useICU26API) {
+ NumberFormat *nf;
+ int32_t i, j;
+
+ UnicodeString output;
+
+ UErrorCode errorCode;
+
+ // TODO: Using printf() here assumes that the runtime encoding is ASCII-friendly
+ // and can therefore be mixed with UTF-8
+
+ for(i=0; i<LENGTHOF(sampleLocaleIDs); ++i) {
+ printf("show currency formatting (method for %s) in the locale \"%s\"\n",
+ useICU26API ? "ICU 2.6" : "before ICU 2.6",
+ sampleLocaleIDs[i]);
+
+ // get a currency formatter for this locale ID
+ errorCode=U_ZERO_ERROR;
+ nf=NumberFormat::createCurrencyInstance(sampleLocaleIDs[i], errorCode);
+ if(U_FAILURE(errorCode)) {
+ printf("NumberFormat::createCurrencyInstance(%s) failed - %s\n",
+ sampleLocaleIDs[i], u_errorName(errorCode));
+ continue;
+ }
+
+ for(j=0; j<LENGTHOF(sampleCurrencies); ++j) {
+ printf(" - format currency \"%s\": ", sampleCurrencies[j]);
+
+ // set the actual currency to be formatted
+ if(useICU26API) {
+ setNumberFormatCurrency_2_6(*nf, sampleCurrencies[j], errorCode);
+ } else {
+ setNumberFormatCurrency_2_4(*nf, sampleCurrencies[j], errorCode);
+ }
+ if(U_FAILURE(errorCode)) {
+ printf("setNumberFormatCurrency(%s) failed - %s\n",
+ sampleCurrencies[j], u_errorName(errorCode));
+ continue;
+ }
+
+ // output=formatted currency value
+ output.remove();
+ nf->format(12345678.93, output);
+ output+=(UChar)0x0a; // '\n'
+ uprintf(output);
+ }
+ }
+}
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/numfmt.sln b/Build/source/libs/icu-xetex/samples/numfmt/numfmt.sln
new file mode 100644
index 00000000000..a9257f05446
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/numfmt.sln
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "numfmt", "numfmt.vcproj", "{721FBD47-E458-4C35-90DA-FF192907D5E2}"
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ ConfigName.0 = Debug
+ ConfigName.1 = Release
+ EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {721FBD47-E458-4C35-90DA-FF192907D5E2}.Debug.ActiveCfg = Debug|Win32
+ {721FBD47-E458-4C35-90DA-FF192907D5E2}.Debug.Build.0 = Debug|Win32
+ {721FBD47-E458-4C35-90DA-FF192907D5E2}.Release.ActiveCfg = Release|Win32
+ {721FBD47-E458-4C35-90DA-FF192907D5E2}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/numfmt.vcproj b/Build/source/libs/icu-xetex/samples/numfmt/numfmt.vcproj
new file mode 100644
index 00000000000..2ccdc2b5a64
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/numfmt.vcproj
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="numfmt"
+ SccProjectName=""
+ SccLocalPath="">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ OptimizeForProcessor="2"
+ AdditionalIncludeDirectories="../../../include"
+ PreprocessorDefinitions="WIN32,_DEBUG,_CONSOLE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Debug/numfmt.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ DebugInformationFormat="4"
+ CompileAs="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuucd.lib icuind.lib"
+ OutputFile=".\Debug/numfmt.exe"
+ LinkIncremental="2"
+ SuppressStartupBanner="TRUE"
+ AdditionalLibraryDirectories="../../../lib"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile=".\Debug/numfmt.pdb"
+ SubSystem="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Debug/numfmt.tlb"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="1"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="../../../include"
+ PreprocessorDefinitions="WIN32,NDEBUG,_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="2"
+ PrecompiledHeaderFile=".\Release/numfmt.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="TRUE"
+ CompileAs="0"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuuc.lib icuin.lib"
+ OutputFile=".\Release/numfmt.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="TRUE"
+ AdditionalLibraryDirectories="../../../lib"
+ ProgramDatabaseFile=".\Release/numfmt.pdb"
+ SubSystem="1"/>
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Release/numfmt.tlb"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+ <File
+ RelativePath=".\capi.c">
+ </File>
+ <File
+ RelativePath=".\main.cpp">
+ </File>
+ <File
+ RelativePath=".\util.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl">
+ <File
+ RelativePath=".\util.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/readme.txt b/Build/source/libs/icu-xetex/samples/numfmt/readme.txt
new file mode 100644
index 00000000000..d652d9b6b57
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/readme.txt
@@ -0,0 +1,61 @@
+Copyright (c) 2002-2005, International Business Machines Corporation and others. All Rights Reserved.
+numfmt: a sample program which displays number formatting in C and C++
+
+This sample demonstrates
+ Formatting a number
+ Outputting text in the default codepage to the console
+
+Files:
+ main.cpp Main source file in C++
+ capi.c C version
+ util.cpp formatted output convenience implementation
+ util.h formatted output convenience header
+ numfmt.sln Windows MSVC workspace. Double-click this to get started.
+ numfmt.vcproj Windows MSVC project file
+
+To Build on Windows
+ 1. Install and build ICU
+ 2. In MSVC, open the workspace file icu\samples\numfmt\numfmt.sln
+ 3. Choose a Debug or Release build.
+ 4. Build.
+
+To Run on Windows
+ 1. Start a command shell window
+ 2. Add ICU's bin directory to the path, e.g.
+ set PATH=c:\icu\bin;%PATH%
+ (Use the path to where ever ICU is on your system.)
+ 3. cd into the numfmt directory, e.g.
+ cd c:\icu\source\samples\numfmt\debug
+ 4. Run it
+ numfmt
+
+To Build on Unixes
+ 1. Build ICU.
+ Specify an ICU install directory when running configure,
+ using the --prefix option. The steps to build ICU will look something
+ like this:
+ cd <icu directory>/source
+ runConfigureICU <platform-name> --prefix <icu install directory> [other options]
+ gmake all
+
+ 2. Install ICU,
+ gmake install
+
+ 3. Compile
+ cd <icu directory>/source/samples/numfmt
+ gmake ICU_PREFIX=<icu install directory)
+
+ To Run on Unixes
+ cd <icu directory>/source/samples/numfmt
+
+ gmake ICU_PREFIX=<icu install directory> check
+ -or-
+
+ export LD_LIBRARY_PATH=<icu install directory>/lib:.:$LD_LIBRARY_PATH
+ numfmt
+
+ Note: The name of the LD_LIBRARY_PATH variable is different on some systems.
+ If in doubt, run the sample using "gmake check", and note the name of
+ the variable that is used there. LD_LIBRARY_PATH is the correct name
+ for Linux and Solaris.
+
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/util.cpp b/Build/source/libs/icu-xetex/samples/numfmt/util.cpp
new file mode 100644
index 00000000000..b4025444991
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/util.cpp
@@ -0,0 +1,117 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2003, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/unistr.h"
+#include "unicode/fmtable.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+enum {
+ U_SPACE=0x20,
+ U_DQUOTE=0x22,
+ U_COMMA=0x2c,
+ U_LEFT_SQUARE_BRACKET=0x5b,
+ U_BACKSLASH=0x5c,
+ U_RIGHT_SQUARE_BRACKET=0x5d,
+ U_SMALL_U=0x75
+};
+
+// Verify that a UErrorCode is successful; exit(1) if not
+void check(UErrorCode& status, const char* msg) {
+ if (U_FAILURE(status)) {
+ printf("ERROR: %s (%s)\n", u_errorName(status), msg);
+ exit(1);
+ }
+ // printf("Ok: %s\n", msg);
+}
+
+// Append a hex string to the target
+static UnicodeString& appendHex(uint32_t number,
+ int8_t digits,
+ UnicodeString& target) {
+ uint32_t digit;
+ while (digits > 0) {
+ digit = (number >> ((--digits) * 4)) & 0xF;
+ target += (UChar)(digit < 10 ? 0x30 + digit : 0x41 - 10 + digit);
+ }
+ return target;
+}
+
+// Replace nonprintable characters with unicode escapes
+UnicodeString escape(const UnicodeString &source) {
+ int32_t i;
+ UnicodeString target;
+ target += (UChar)U_DQUOTE;
+ for (i=0; i<source.length(); ++i) {
+ UChar ch = source[i];
+ if (ch < 0x09 || (ch > 0x0D && ch < 0x20) || ch > 0x7E) {
+ (target += (UChar)U_BACKSLASH) += (UChar)U_SMALL_U;
+ appendHex(ch, 4, target);
+ } else {
+ target += ch;
+ }
+ }
+ target += (UChar)U_DQUOTE;
+ return target;
+}
+
+// Print the given string to stdout using the UTF-8 converter
+void uprintf(const UnicodeString &str) {
+ char stackBuffer[100];
+ char *buf = 0;
+
+ int32_t bufLen = str.extract(0, 0x7fffffff, stackBuffer, sizeof(stackBuffer), "UTF-8");
+ if(bufLen < sizeof(stackBuffer)) {
+ buf = stackBuffer;
+ } else {
+ buf = new char[bufLen + 1];
+ bufLen = str.extract(0, 0x7fffffff, buf, bufLen + 1, "UTF-8");
+ }
+ printf("%s", buf);
+ if(buf != stackBuffer) {
+ delete buf;
+ }
+}
+
+// Create a display string for a formattable
+UnicodeString formattableToString(const Formattable& f) {
+ switch (f.getType()) {
+ case Formattable::kDate:
+ // TODO: Finish implementing this
+ return UNICODE_STRING_SIMPLE("Formattable_DATE_TBD");
+ case Formattable::kDouble:
+ {
+ char buf[256];
+ sprintf(buf, "%gD", f.getDouble());
+ return UnicodeString(buf, "");
+ }
+ case Formattable::kLong:
+ case Formattable::kInt64:
+ {
+ char buf[256];
+ sprintf(buf, "%ldL", f.getLong());
+ return UnicodeString(buf, "");
+ }
+ case Formattable::kString:
+ return UnicodeString((UChar)U_DQUOTE).append(f.getString()).append((UChar)U_DQUOTE);
+ case Formattable::kArray:
+ {
+ int32_t i, count;
+ const Formattable* array = f.getArray(count);
+ UnicodeString result((UChar)U_LEFT_SQUARE_BRACKET);
+ for (i=0; i<count; ++i) {
+ if (i > 0) {
+ (result += (UChar)U_COMMA) += (UChar)U_SPACE;
+ }
+ result += formattableToString(array[i]);
+ }
+ result += (UChar)U_RIGHT_SQUARE_BRACKET;
+ return result;
+ }
+ default:
+ return UNICODE_STRING_SIMPLE("INVALID_Formattable");
+ }
+}
diff --git a/Build/source/libs/icu-xetex/samples/numfmt/util.h b/Build/source/libs/icu-xetex/samples/numfmt/util.h
new file mode 100644
index 00000000000..e50ef7aae2c
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/numfmt/util.h
@@ -0,0 +1,20 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1999-2002, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#include "unicode/unistr.h"
+#include "unicode/fmtable.h"
+
+// Verify that a UErrorCode is successful; exit(1) if not
+void check(UErrorCode& status, const char* msg);
+
+// Replace nonprintable characters with unicode escapes
+UnicodeString escape(const UnicodeString &source);
+
+// Print the given string to stdout
+void uprintf(const UnicodeString &str);
+
+// Create a display string for a formattable
+UnicodeString formattableToString(const Formattable& f);