From a90b5bfd83bfd6dbd4fbcc7a4be9c64c04bbfbed Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 24 Sep 2020 17:59:22 -0500 Subject: [PATCH] Iuc43 (#14) * ICU-13668 Rebase of iuc42 branch onto master - the "iuc42" branch b14a81fec744b553294d5d3d93c34d41dbfc19e8 is in this commit from last year. * ICU-13668 iuc43 updates for iuc43 - automated testing of C demos - delete old "icufacts" (from iuc37), add top level instruction * ICU-13668 iuc43 test J iucsamples too! * ICU-13668 iuc43 use travis mvn instead of docker * fixup! ICU-13668 iuc43 use travis mvn instead of docker * fixup! ICU-13668 iuc43 test J iucsamples too! * Update readme.txt * Match https://github.com/srl295/srl295-slides/commit/bc71356b44117386ee1be95e225cc78341cf0fe5 * iuc43 fixes - use '-e utf-8' to not default the genrb build - add an error for ICU4C<62.x API --- .travis.yml | 9 +- README | 4 +- icufacts/c/all.sh | 12 -- icufacts/c/check.sh | 12 -- icufacts/c/clean.sh | 10 -- icufacts/c/config.mk | 16 --- icufacts/c/icuconfig.mk | 6 - icufacts/c/icupc.mk | 9 -- icufacts/c/icusrc.mk | 20 --- icufacts/c/iucsamples.h | 34 ----- icufacts/c/popdata/Makefile | 3 - icufacts/c/popdata/popdata.cpp | 24 ---- icufacts/c/popdata/popdata_inc.h | 130 ------------------ icufacts/c/readme.txt | 44 ------ icufacts/c/s00_hello/Makefile | 2 - icufacts/c/s00_hello/s00_hello.cpp | 19 --- icufacts/c/s13_hello/Makefile | 2 - icufacts/c/s13_hello/s13_hello.cpp | 24 ---- icufacts/c/s30_reshello/Makefile | 3 - icufacts/c/s30_reshello/reshello/es.txt | 3 - icufacts/c/s30_reshello/reshello/mt.txt | 3 - icufacts/c/s30_reshello/reshello/root.txt | 3 - icufacts/c/s30_reshello/s30_reshello.cpp | 16 --- icufacts/c/s40_popmsg/Makefile | 4 - icufacts/c/s40_popmsg/popmsg/en.txt | 3 - icufacts/c/s40_popmsg/popmsg/es.txt | 14 -- icufacts/c/s40_popmsg/popmsg/ja.txt | 3 - icufacts/c/s40_popmsg/popmsg/root.txt | 13 -- icufacts/c/s40_popmsg/s40_popmsg.cpp | 72 ---------- icufacts/c/s50_popsort/Makefile | 7 - icufacts/c/s50_popsort/s50_popsort.cpp | 100 -------------- icufacts/c/s99_sort/Makefile | 2 - icufacts/c/s99_sort/s99_sort.cpp | 65 --------- icufacts/c/samples.mk | 19 --- icufacts/c/simple.mk | 30 ---- icufacts/readme.txt | 11 -- iucsamples/c/.gitignore | 5 + iucsamples/c/config.mk | 6 +- iucsamples/c/data/Makefile | 9 +- iucsamples/c/data/data.vcxproj | 4 +- iucsamples/c/data/es.txt | 2 +- .../c => iucsamples/c/hellomsg}/Makefile | 12 +- iucsamples/c/hellomsg/hellomsg.cpp | 43 ++++++ iucsamples/c/icupc.mk | 19 ++- iucsamples/c/iucsamples.h | 5 + iucsamples/c/readme.txt | 10 +- .../c/s09_test/{s09_test.cpp => s09_test.c} | 7 +- iucsamples/c/s09a_test/Makefile | 4 + iucsamples/c/s09a_test/s09a_test.cpp | 30 ++++ .../s13_hello/{s13_hello.cpp => s13_hello.c} | 0 iucsamples/c/s13a_hello/Makefile | 4 + iucsamples/c/s13a_hello/s13a_hello.cpp | 25 ++++ iucsamples/c/s23_brki/s23_brki.cpp | 25 ++-- iucsamples/c/s27_brkl/s27_brkl.cpp | 1 + iucsamples/c/s34_coll/s34_coll.cpp | 2 +- iucsamples/c/s88_units/Makefile | 4 + iucsamples/c/s88_units/s88_units.cpp | 46 +++++++ iucsamples/c/s99_compact/Makefile | 4 + iucsamples/c/s99_compact/s99_compact.cpp | 65 +++++++++ iucsamples/j/Makefile | 44 ------ iucsamples/j/data/myapp/es.res | Bin 224 -> 0 bytes iucsamples/j/data/myapp/root.res | Bin 208 -> 0 bytes iucsamples/j/icu2work/.gitignore | 7 + iucsamples/j/icu2work/pom.xml | 114 +++++++++++++++ .../ibm/us/srloomis/demo/icu2work/.gitignore | 4 + .../us/srloomis/demo/icu2work/BadMessage.java | 26 ++++ .../demo/icu2work/CollateMessage.java | 29 ++++ .../srloomis/demo/icu2work/GoodMessage.java | 29 ++++ .../ibm/us/srloomis/demo/icu2work/Hello.java | 27 ++++ .../us/srloomis/demo/icu2work/impl/.gitignore | 3 + .../demo/icu2work/impl/PopulationData.java | 84 +++++++++++ .../icu2work/impl/SupplementalUtilities.java | 84 +++++++++++ .../demo/icu2work/BadMessage.properties | 3 + .../demo/icu2work/GoodMessage.properties | 3 + .../ibm/us/srloomis/demo/icu2work/.gitignore | 2 + .../us/srloomis/demo/icu2work/AppTest.java | 35 +++++ iucsamples/j/readme.txt | 16 --- iucsamples/j/s49.java | 11 -- iucsamples/j/s52.java | 30 ---- iucsamples/j/s56.java | 48 ------- iucsamples/j/s58.java | 29 ---- iucsamples/readme.txt | 4 +- 82 files changed, 757 insertions(+), 958 deletions(-) delete mode 100755 icufacts/c/all.sh delete mode 100755 icufacts/c/check.sh delete mode 100755 icufacts/c/clean.sh delete mode 100644 icufacts/c/config.mk delete mode 100644 icufacts/c/icuconfig.mk delete mode 100644 icufacts/c/icupc.mk delete mode 100644 icufacts/c/icusrc.mk delete mode 100644 icufacts/c/iucsamples.h delete mode 100644 icufacts/c/popdata/Makefile delete mode 100644 icufacts/c/popdata/popdata.cpp delete mode 100644 icufacts/c/popdata/popdata_inc.h delete mode 100644 icufacts/c/readme.txt delete mode 100644 icufacts/c/s00_hello/Makefile delete mode 100644 icufacts/c/s00_hello/s00_hello.cpp delete mode 100644 icufacts/c/s13_hello/Makefile delete mode 100644 icufacts/c/s13_hello/s13_hello.cpp delete mode 100644 icufacts/c/s30_reshello/Makefile delete mode 100644 icufacts/c/s30_reshello/reshello/es.txt delete mode 100644 icufacts/c/s30_reshello/reshello/mt.txt delete mode 100644 icufacts/c/s30_reshello/reshello/root.txt delete mode 100644 icufacts/c/s30_reshello/s30_reshello.cpp delete mode 100644 icufacts/c/s40_popmsg/Makefile delete mode 100644 icufacts/c/s40_popmsg/popmsg/en.txt delete mode 100644 icufacts/c/s40_popmsg/popmsg/es.txt delete mode 100644 icufacts/c/s40_popmsg/popmsg/ja.txt delete mode 100644 icufacts/c/s40_popmsg/popmsg/root.txt delete mode 100644 icufacts/c/s40_popmsg/s40_popmsg.cpp delete mode 100644 icufacts/c/s50_popsort/Makefile delete mode 100644 icufacts/c/s50_popsort/s50_popsort.cpp delete mode 100644 icufacts/c/s99_sort/Makefile delete mode 100644 icufacts/c/s99_sort/s99_sort.cpp delete mode 100644 icufacts/c/samples.mk delete mode 100644 icufacts/c/simple.mk delete mode 100644 icufacts/readme.txt create mode 100644 iucsamples/c/.gitignore rename {icufacts/c => iucsamples/c/hellomsg}/Makefile (51%) create mode 100644 iucsamples/c/hellomsg/hellomsg.cpp rename iucsamples/c/s09_test/{s09_test.cpp => s09_test.c} (64%) create mode 100644 iucsamples/c/s09a_test/Makefile create mode 100644 iucsamples/c/s09a_test/s09a_test.cpp rename iucsamples/c/s13_hello/{s13_hello.cpp => s13_hello.c} (100%) create mode 100644 iucsamples/c/s13a_hello/Makefile create mode 100644 iucsamples/c/s13a_hello/s13a_hello.cpp create mode 100644 iucsamples/c/s88_units/Makefile create mode 100644 iucsamples/c/s88_units/s88_units.cpp create mode 100644 iucsamples/c/s99_compact/Makefile create mode 100644 iucsamples/c/s99_compact/s99_compact.cpp delete mode 100644 iucsamples/j/Makefile delete mode 100644 iucsamples/j/data/myapp/es.res delete mode 100644 iucsamples/j/data/myapp/root.res create mode 100644 iucsamples/j/icu2work/.gitignore create mode 100644 iucsamples/j/icu2work/pom.xml create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/.gitignore create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/BadMessage.java create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/CollateMessage.java create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/GoodMessage.java create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/Hello.java create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/.gitignore create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/PopulationData.java create mode 100644 iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/SupplementalUtilities.java create mode 100644 iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/BadMessage.properties create mode 100644 iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/GoodMessage.properties create mode 100644 iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/.gitignore create mode 100644 iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/AppTest.java delete mode 100644 iucsamples/j/readme.txt delete mode 100644 iucsamples/j/s49.java delete mode 100644 iucsamples/j/s52.java delete mode 100644 iucsamples/j/s56.java delete mode 100644 iucsamples/j/s58.java diff --git a/.travis.yml b/.travis.yml index 9052ce8a..ca2c4f7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,16 @@ sudo: required +language: java +jdk: + - openjdk8 services: docker install: true script: - - '( cd icu4jweb && docker run -it --rm -v $HOME/.m2/:/root/.m2/ -v $(pwd)/:/usr/src -w /usr/src maven:3-jdk-8 mvn package && sh build-docker.sh )' + - mvn -f icu4jweb/pom.xml package + - '( cd icu4jweb && sh build-docker.sh )' - '( cd icu-kube && sh build.sh )' + - '( cd iucsamples/c && docker run --rm -v $HOME/.apk:/etc/apk/cache -v $(pwd)/:/usr/src -w /usr/src alpine:edge sh -c "apk --update add gcc make g++ bsd-compat-headers pkgconfig icu-dev && make all check" )' + - mvn -f iucsamples/j/icu2work/pom.xml test cache: directories: - $HOME/.m2 + - $HOME/.apk diff --git a/README b/README index 27d82303..055cbc08 100644 --- a/README +++ b/README @@ -8,11 +8,13 @@ more information on the ICU: URL: http://icu-project.org/ - If you have an application that is written using the ICU that you would like to contribute, join the ICU mailing list [above URL] and contact us. +- The "iucsamples" directory contains samples for the +Unicode conference and has its own +build instructions. BUILDING -------- diff --git a/icufacts/c/all.sh b/icufacts/c/all.sh deleted file mode 100755 index 51028eb2..00000000 --- a/icufacts/c/all.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -#make -C data - -for dir in `ls`; -do - if [ -f "${dir}/Makefile" ]; - then - make -C "${dir}" - fi -done diff --git a/icufacts/c/check.sh b/icufacts/c/check.sh deleted file mode 100755 index 3fe1bf32..00000000 --- a/icufacts/c/check.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -#make -C data - -for dir in `ls`; -do - if [ -f "${dir}/Makefile" ]; - then - make -C "${dir}" check - fi -done diff --git a/icufacts/c/clean.sh b/icufacts/c/clean.sh deleted file mode 100755 index 3202474d..00000000 --- a/icufacts/c/clean.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -for dir in `ls`; -do - if [ -f "${dir}/Makefile" ]; - then - make -C "${dir}" clean - fi -done diff --git a/icufacts/c/config.mk b/icufacts/c/config.mk deleted file mode 100644 index 2fa9f8c6..00000000 --- a/icufacts/c/config.mk +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2010-2011 IBM Corporation and Others. All Rights Reserved. - --include ../local.mk --include local.mk -ifneq ($(icubuild),) -include ../icusrc.mk -endif - -ifeq ($(ICU_VER),) -ifneq ($(shell pkg-config --silence-errors icu-io --modversion),) -include ../icupc.mk -endif -endif -ifeq ($(ICU_VER),) -include ../icuconfig.mk -endif diff --git a/icufacts/c/icuconfig.mk b/icufacts/c/icuconfig.mk deleted file mode 100644 index 5517cf01..00000000 --- a/icufacts/c/icuconfig.mk +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. -# icu-config version -ICU_VER=$(shell icu-config --version) -LDFLAGS+=$(shell icu-config --ldflags --ldflags-icuio) -CPPFLAGS+=$(shell icu-config --cppflags) -INVOKE=$(shell icu-config --invoke) diff --git a/icufacts/c/icupc.mk b/icufacts/c/icupc.mk deleted file mode 100644 index ad6d274f..00000000 --- a/icufacts/c/icupc.mk +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. -# pkg-config version - -ICU_VER=$(shell pkg-config icu-io --modversion) -LDFLAGS+=$(shell pkg-config icu-io --libs) -CPPFLAGS+=$(shell pkg-config icu-io --cflags) -#INVOKE=$(shell icu-config --invoke) -# assume can invoke from command line -INVOKE= diff --git a/icufacts/c/icusrc.mk b/icufacts/c/icusrc.mk deleted file mode 100644 index a425325b..00000000 --- a/icufacts/c/icusrc.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2010-2011 IBM Corporation and Others. All Rights Reserved. -# for running against a non-installed ICU: set icubuild - -srcdir=$(shell sed -ne "s%^srcdir='\(.*\)'%\1%gp" < "$(icubuild)/config.status" ) - -ifeq ($(srcdir),) -$(error could not find $$srcdir - does $$icubuild point to a built ICU?) -endif -ifeq ($(srcdir),.) -srcdir:=$(icubuild) -endif - -cross_buildroot:=$(icubuild) -include $(icubuild)/config/icucross.mk - -ICULIBDIR=$(icubuild)/lib -LDFLAGS+=-L$(ICULIBDIR) -licuuc -licui18n -licuio -CPPFLAGS+=-I$(srcdir)/common -I$(srcdir)/i18n -I$(srcdir)/io -I$(icubuild)/common -ICU_VER=$(CROSS_ICU_VERSION) - diff --git a/icufacts/c/iucsamples.h b/icufacts/c/iucsamples.h deleted file mode 100644 index 6653e6b8..00000000 --- a/icufacts/c/iucsamples.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. */ -/* These are just here to reduce code size of samples */ - -#ifndef _IUCSAMPLES -#define _IUCSAMPLES - -#include -#include -#include -#include -#include -#include -#include - -// C++ includes -#ifdef __cplusplus -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -/** - * \def ASSERT_OK - * @param x status param - * if U_FAILURE(x) then a message will be printed. - */ -#define ASSERT_OK(x) if(U_FAILURE(x)) { u_printf("%s:%d: ICU Failure %s\n", __FILE__, __LINE__, u_errorName(x)); } - -#endif diff --git a/icufacts/c/popdata/Makefile b/icufacts/c/popdata/Makefile deleted file mode 100644 index d4499dff..00000000 --- a/icufacts/c/popdata/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# -include ../simple.mk - diff --git a/icufacts/c/popdata/popdata.cpp b/icufacts/c/popdata/popdata.cpp deleted file mode 100644 index 11ab46b8..00000000 --- a/icufacts/c/popdata/popdata.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "../iucsamples.h" -#include "popdata_inc.h" - -// this is just a test program for the population data class - -int main() { - UErrorCode status = U_ZERO_ERROR; - - int32_t nTerr; - TerritoryEntry **ent = getTerritoryEntries(Locale::getDefault(), nTerr, status); - ASSERT_OK(status); - - u_printf("count=%d\n", nTerr); - for(int i=0;igetPopulation(), - ent[i]->getTerritoryName().length(), ent[i]->getTerritoryName().getBuffer() ); - delete ent[i]; - } - delete [] ent; -} - -// Local Variables: -// compile-command: "make check" -// End: diff --git a/icufacts/c/popdata/popdata_inc.h b/icufacts/c/popdata/popdata_inc.h deleted file mode 100644 index c7cca971..00000000 --- a/icufacts/c/popdata/popdata_inc.h +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. -// Population Data source. -// Written inline for ease of sample programs. -#include "../iucsamples.h" -#include - -class TerritoryEntry { - public: - TerritoryEntry(const UnicodeString &countryName, - int64_t population) : fTerritoryName(countryName), fPopulation(population) {} - const UnicodeString &getTerritoryName() const { return fTerritoryName; } - int64_t getPopulation() const { return fPopulation; } - private: - int64_t fPopulation; - UnicodeString fTerritoryName; - public: - /** - * @param locale display locale - * @param count number of territories, on exit - * @param status error code (must be U_SUCCESS(status) on entry) - * @return array of pointers to TerritoryEntry. Caller owns the pointers and the obj. - */ - static inline TerritoryEntry **getTerritoryEntries(const Locale &locale, int32_t &count, UErrorCode &status); -}; - -static double ldml2d(int32_t n); - -TerritoryEntry **TerritoryEntry::getTerritoryEntries(const Locale& loc, int32_t &nTerr, UErrorCode &status) { - // Note: format of supplementalData is NOT STATIC and may change. It is internal to ICU. - LocalUResourceBundlePointer suppData(ures_openDirect(NULL, "supplementalData", &status)); - LocalUResourceBundlePointer territoryInfo(ures_getByKey(suppData.getAlias(), "territoryInfo", NULL, &status)); - nTerr = ures_getSize(territoryInfo.getAlias()); - - if(U_FAILURE(status)) { - return NULL; - } - - TerritoryEntry **entries = new TerritoryEntry* [nTerr]; - LocalUResourceBundlePointer entry; - int n=0; - for(n=0;ures_hasNext(territoryInfo.getAlias());n++) { - { - UResourceBundle *rawEntry = entry.orphan(); - entry.adoptInstead(ures_getNextResource(territoryInfo.getAlias(), rawEntry, &status)); - } - LocalUResourceBundlePointer territoryF(ures_getByKey(entry.getAlias(), "territoryF", NULL, &status)); - int32_t len; - const int32_t *vec = ures_getIntVector(territoryF.getAlias(), &len, &status); - - if(n>=nTerr) { - status = U_BUFFER_OVERFLOW_ERROR; - return entries; - } else if(U_FAILURE(status)) { - return entries; - } - - // now we have the entry - // territoryF = { gdp, literacy, population } - const char *terrID = ures_getKey(entry.getAlias()); // ex - "CD" - Locale territory("und", terrID); - UnicodeString territoryName; - entries[n] = new TerritoryEntry(territory.getDisplayCountry(loc, territoryName), ldml2d(vec[2])); - } - - return entries; -} - -// shim -static TerritoryEntry **getTerritoryEntries(const Locale& loc, int32_t &nTerr, UErrorCode &status) { - return TerritoryEntry::getTerritoryEntries(loc, nTerr, status); -} - -/** - * Convert LDML2ICUConverter format floating point (territoryF, etc) - * into double. - * See: SupplementalMapper.java - function "&exp" - * @param n input number, such as -48123456 - * @return double value, such as -123.456 - * @internal - */ -static double ldml2d(int32_t n) { - if(n == 0) { - return 0.; - } - bool neg = false; - if(n < 0) { - n = -n; - neg = true; - } - int exp = (n/1000000); - n -= (exp * 1000000); - int sexp = exp - 50; // signed exponent - double d = n; - d = d * pow(10, (sexp-5)); // -5 because 50 isn't quite right.. - if(neg) { - d = -d; - } - return d; -} - -#if 0 // test program -int main() -{ - printf("foo.\n"); - - int32_t junk[] = { - 49990000, // 99% - 48680000, // 6.8% - 57344400, // ? - 52940000, // ? - 0, - -48123456, // gets -0.012346 not -123.456 - -52123456, // this one gets -123.456 - 46100000, - 63146600 - }; - - for(int i=0;i ", junk[i]); - int32_t n = junk[i]; - - double d = ldml2d(n); - printf(" %.8f", d); - printf("\n"); - } - - return 0; -} -#endif - diff --git a/icufacts/c/readme.txt b/icufacts/c/readme.txt deleted file mode 100644 index 0ec6317a..00000000 --- a/icufacts/c/readme.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2010-2012 IBM Corporation and Others. All Rights Reserved. - - -Note: - These samples now use "u_printf" which was added in ICU 49. You can get equivalent -behavior on older ICUs with: - UFILE *out = u_finit(stdout, loc, NULL); - u_fprintf(out, "\n\nlocale=%s\n", loc); - ... - u_fclose(out); - ----- - - -Windows Visual Studio: - -Use the project file iucsamples.sln. -Set variable IcuDir to the root of your ICU build (containing bin, lib, include) -set PATH=%IcuDir%\bin;%PATH% - - -UNIXes: see below. - - -To locate ICU for the purpose of these samples, ensure one of the following is true: - -1. ICU built, not installed: - Set the variable "icubuild" to point to a built ICU source directory (in-source or out of source) - Example: add to 'local.mk' this line: "icubuild=/home/srl/icu/source" being a directory where ICU is built. - Example: 'export icubuild=/tmp/icu-build' - -2. ICU built, installed, pkg-config is installed: - (PKG_CONFIG_PATH or equivalent should point to icu's .pc files). - -3. ICU built, installed, icu-config is on the $PATH - -Note: - Make sure icu's bin and sbin dirs are on the PATH. - You may want to set [DY]LD_LIBRARY_PATH to include icu's lib dir also. - -To build and run all samples, just run 'make check'. To build an individual sample, run 'make check' from inside that directory. - -The "icurun" script can also be used to build individual files. See - http://source.icu-project.org/repos/icu/tools/trunk/scripts/icurun diff --git a/icufacts/c/s00_hello/Makefile b/icufacts/c/s00_hello/Makefile deleted file mode 100644 index eae4fb6f..00000000 --- a/icufacts/c/s00_hello/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -include ../simple.mk - diff --git a/icufacts/c/s00_hello/s00_hello.cpp b/icufacts/c/s00_hello/s00_hello.cpp deleted file mode 100644 index 7d169155..00000000 --- a/icufacts/c/s00_hello/s00_hello.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. - -#include "../iucsamples.h" -#include - -int main() { - UErrorCode status = U_ZERO_ERROR; - u_init(&status); - if(U_FAILURE(status)) { puts(u_errorName(status)); return 1; } // hereafter: ASSERT_OK - UnicodeString msg("Hello, "); - msg.append("World"); - msg.append(0x2603); - std::cout << msg << std::endl; - return 0; -} - -// Local Variables: -// compile-command: "icurun s13_hello.cpp" -// End: diff --git a/icufacts/c/s13_hello/Makefile b/icufacts/c/s13_hello/Makefile deleted file mode 100644 index eae4fb6f..00000000 --- a/icufacts/c/s13_hello/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -include ../simple.mk - diff --git a/icufacts/c/s13_hello/s13_hello.cpp b/icufacts/c/s13_hello/s13_hello.cpp deleted file mode 100644 index 627a34a1..00000000 --- a/icufacts/c/s13_hello/s13_hello.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. - -#include "../iucsamples.h" - -int main() { - UErrorCode status = U_ZERO_ERROR; - ULocaleDisplayNames *names = uldn_open(NULL, // = default - ULDN_DIALECT_NAMES, - &status); - UChar result[256]; - int32_t len = uldn_regionDisplayName(names, "001", result, 256, &status); - uldn_close(names); - ASSERT_OK(status); - UnicodeString msg("Hello, "); - msg.append(result, len); - msg.append(0x2603); - std::cout << msg << std::endl; - return 0; -} - -// Local Variables: -// compile-command: "icurun s13_hello.cpp" -// End: - diff --git a/icufacts/c/s30_reshello/Makefile b/icufacts/c/s30_reshello/Makefile deleted file mode 100644 index 5e2e103c..00000000 --- a/icufacts/c/s30_reshello/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. -RESNAME=reshello -include ../simple.mk diff --git a/icufacts/c/s30_reshello/reshello/es.txt b/icufacts/c/s30_reshello/reshello/es.txt deleted file mode 100644 index eede7748..00000000 --- a/icufacts/c/s30_reshello/reshello/es.txt +++ /dev/null @@ -1,3 +0,0 @@ -es { - hello { "¡Hola!" } -} diff --git a/icufacts/c/s30_reshello/reshello/mt.txt b/icufacts/c/s30_reshello/reshello/mt.txt deleted file mode 100644 index 3e21aab2..00000000 --- a/icufacts/c/s30_reshello/reshello/mt.txt +++ /dev/null @@ -1,3 +0,0 @@ -mt { - hello { "Merħba!" } -} diff --git a/icufacts/c/s30_reshello/reshello/root.txt b/icufacts/c/s30_reshello/reshello/root.txt deleted file mode 100644 index 45ce9e05..00000000 --- a/icufacts/c/s30_reshello/reshello/root.txt +++ /dev/null @@ -1,3 +0,0 @@ -root { - hello { "Hello!" } -} diff --git a/icufacts/c/s30_reshello/s30_reshello.cpp b/icufacts/c/s30_reshello/s30_reshello.cpp deleted file mode 100644 index 68c1d05e..00000000 --- a/icufacts/c/s30_reshello/s30_reshello.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. -#include "../iucsamples.h" - -int main() -{ - - UErrorCode status = U_ZERO_ERROR; - u_setDataDirectory("out"); // this is where the data is generated, see Makefile - Locale locale = Locale::getDefault(); -// BEGIN SAMPLE - ResourceBundle resourceBundle("reshello", locale, status); - UnicodeString thing = resourceBundle.getStringEx("hello", status); - std::cout << thing << std::endl; - ASSERT_OK(status); - return 0; -} diff --git a/icufacts/c/s40_popmsg/Makefile b/icufacts/c/s40_popmsg/Makefile deleted file mode 100644 index fc7cc403..00000000 --- a/icufacts/c/s40_popmsg/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. -RESNAME=popmsg -include ../simple.mk - diff --git a/icufacts/c/s40_popmsg/popmsg/en.txt b/icufacts/c/s40_popmsg/popmsg/en.txt deleted file mode 100644 index 403c8ec4..00000000 --- a/icufacts/c/s40_popmsg/popmsg/en.txt +++ /dev/null @@ -1,3 +0,0 @@ -en { - // empty -} diff --git a/icufacts/c/s40_popmsg/popmsg/es.txt b/icufacts/c/s40_popmsg/popmsg/es.txt deleted file mode 100644 index 2d9c3002..00000000 --- a/icufacts/c/s40_popmsg/popmsg/es.txt +++ /dev/null @@ -1,14 +0,0 @@ -es { -// welcome { "¡Hola! Tenemos {territoryCount, number} regiónes." } - welcome { "Mi lengua es {myLanguage}, y hoy es {today, date}. Tenemos {territoryCount, number} regiónes." } - - // #1 (non plural) - // info { "En la región de “{territory}” hay {population, number} personas." } - - // #2 (plural) - info { "{population, plural, " - " =0{{territory} no hay ninguno personas.}" - " one{En la región de “{territory}” hay uno persona!}" - " other{En la región de “{territory}” hay # personas.}}" } - -} diff --git a/icufacts/c/s40_popmsg/popmsg/ja.txt b/icufacts/c/s40_popmsg/popmsg/ja.txt deleted file mode 100644 index 65b4e44f..00000000 --- a/icufacts/c/s40_popmsg/popmsg/ja.txt +++ /dev/null @@ -1,3 +0,0 @@ -ja { - info { "{territory}には、{population,number}人います。" } -} diff --git a/icufacts/c/s40_popmsg/popmsg/root.txt b/icufacts/c/s40_popmsg/popmsg/root.txt deleted file mode 100644 index d7dc8144..00000000 --- a/icufacts/c/s40_popmsg/popmsg/root.txt +++ /dev/null @@ -1,13 +0,0 @@ -root { - welcome { "My language is {myLanguage} and today is {today, date}. We have {territoryCount, number} territories." } - - // Three versions. Uncomment as needed. - - // #1 this is the first cut - no plurals. - //info { "The territory of {territory} has {population} persons." } - - // #2 this is the second try - split out each pluralization by sentence. - info { "{population, plural, =0{{territory} has a population of zero.} one{Only one person lives on {territory}!} other{The territory of {territory} has # persons.}}" - } -} - diff --git a/icufacts/c/s40_popmsg/s40_popmsg.cpp b/icufacts/c/s40_popmsg/s40_popmsg.cpp deleted file mode 100644 index 38935144..00000000 --- a/icufacts/c/s40_popmsg/s40_popmsg.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "../iucsamples.h" -#include "../popdata/popdata_inc.h" - -// Now we're starting to put things together. - -int main() { - UErrorCode status = U_ZERO_ERROR; - Locale defaultLocaleId = Locale::getDefault(); - int32_t territoryCount; // == number of territories - u_setDataDirectory("out"); // this is where the data is generated, see Makefile - - TerritoryEntry **territoryList = TerritoryEntry::getTerritoryEntries(defaultLocaleId, territoryCount, status); - ASSERT_OK(status); - - // First, read the messages. - ResourceBundle resourceBundle("popmsg", defaultLocaleId, status); - ASSERT_OK(status); - - // Print the welcome message. - { - LocalPointer - ldn(LocaleDisplayNames::createInstance(defaultLocaleId, - ULDN_DIALECT_NAMES)); - - UnicodeString myLanguage; - ldn->localeDisplayName(defaultLocaleId, myLanguage); - // "American English" - - UnicodeString world; - ldn->regionDisplayName("001",world); - // "World" - - UnicodeString welcome = resourceBundle.getStringEx("welcome", status); - UnicodeString names[] = { - "myLanguage", "today", "territoryCount" - }; - Formattable args[] = { - myLanguage, Calendar::getNow(), territoryCount - }; - MessageFormat fmt(welcome, defaultLocaleId, status); - UnicodeString result; - fmt.format(names, args, 3, result, status); - ASSERT_OK(status); - std::cout << result << std::endl; - } - - { - // set up the 'info' messageformat. - UnicodeString info = resourceBundle.getStringEx("info", status); - MessageFormat fmt(info, defaultLocaleId, status); - UnicodeString names[] = { - "territory", - "population" - }; - for(int i=0;igetTerritoryName(), - territoryList[i]->getPopulation() - }; - result = fmt.format(names, args, 2, result, status); - ASSERT_OK(status); - std::cout << result << std::endl; - delete territoryList[i]; // cleanup. - } - } - delete [] territoryList; -} - -// Local Variables: -// compile-command: "make check" -// End: diff --git a/icufacts/c/s50_popsort/Makefile b/icufacts/c/s50_popsort/Makefile deleted file mode 100644 index 051801eb..00000000 --- a/icufacts/c/s50_popsort/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2010-2013 IBM Corporation and Others. All Rights Reserved. -RESNAME=popmsg -# share the src translations -RESPAR=../s40_popmsg/ -include ../simple.mk - - diff --git a/icufacts/c/s50_popsort/s50_popsort.cpp b/icufacts/c/s50_popsort/s50_popsort.cpp deleted file mode 100644 index 5153c18c..00000000 --- a/icufacts/c/s50_popsort/s50_popsort.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "../iucsamples.h" -#include "../popdata/popdata_inc.h" -#include -#include - -/** - * A comparison object for std::sort which compares two TerritoryEntries - * according to the Collator given. - * Note: UnicodeString is handled here, but UChar* could be handled similarly. - */ -class CollatorLessThan : public std::binary_function { -public: - /** - * @param coll the Collator to use. Aliased, not adopted. - * @param status error status from comparison functions. U_SUCCESS(status) should be TRUE on entry. Check the error value on exit from the sort function. NOTE: this reference is retained for the life of the CollatorLessThan object. - */ - CollatorLessThan(Collator &coll, UErrorCode &status) : fColl(coll), fStatus(status) {} - inline bool operator()(const TerritoryEntry* a, const TerritoryEntry* b) { - return (fColl.compare(a->getTerritoryName(), b->getTerritoryName(), fStatus) == UCOL_LESS); - } -private: - Collator &fColl; - UErrorCode &fStatus; -}; - - -// Sort the list by collator. - - -int main() { - UErrorCode status = U_ZERO_ERROR; - Locale defaultLocaleId = Locale::getDefault(); - int32_t territoryCount; // == number of territories - u_setDataDirectory("out"); // this is where the data is generated, see Makefile - - TerritoryEntry **territoryList = TerritoryEntry::getTerritoryEntries(defaultLocaleId, territoryCount, status); - ASSERT_OK(status); - - // Create collator and sort the territories - LocalPointer coll(Collator::createInstance(defaultLocaleId, status)); - std::sort(territoryList, territoryList+territoryCount, CollatorLessThan(*coll, status)); - - // First, read the messages. - ResourceBundle resourceBundle("popmsg", defaultLocaleId, status); - ASSERT_OK(status); - - // Print the welcome message. - { - LocalPointer - ldn(LocaleDisplayNames::createInstance(defaultLocaleId, - ULDN_DIALECT_NAMES)); - - UnicodeString myLanguage; - ldn->localeDisplayName(defaultLocaleId, myLanguage); - // "American English" - - UnicodeString world; - ldn->regionDisplayName("001",world); - // "World" - - UnicodeString welcome = resourceBundle.getStringEx("welcome", status); - UnicodeString names[] = { - "myLanguage", "today", "territoryCount" - }; - Formattable args[] = { - myLanguage, Calendar::getNow(), territoryCount - }; - MessageFormat fmt(welcome, defaultLocaleId, status); - UnicodeString result; - fmt.format(names, args, 3, result, status); - ASSERT_OK(status); - std::cout << result << std::endl; - } - - { - // set up the 'info' messageformat. - UnicodeString info = resourceBundle.getStringEx("info", status); - MessageFormat fmt(info, defaultLocaleId, status); - UnicodeString names[] = { - "territory", - "population" - }; - for(int i=0;igetTerritoryName(), - territoryList[i]->getPopulation() - }; - result = fmt.format(names, args, 2, result, status); - ASSERT_OK(status); - std::cout << result << std::endl; - delete territoryList[i]; // cleanup. - } - } - delete [] territoryList; -} - -// Local Variables: -// compile-command: "make check" -// End: diff --git a/icufacts/c/s99_sort/Makefile b/icufacts/c/s99_sort/Makefile deleted file mode 100644 index 52b87292..00000000 --- a/icufacts/c/s99_sort/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -# Copyright (c) 2013 IBM Corporation and Others. All Rights Reserved. -include ../simple.mk diff --git a/icufacts/c/s99_sort/s99_sort.cpp b/icufacts/c/s99_sort/s99_sort.cpp deleted file mode 100644 index d2645d27..00000000 --- a/icufacts/c/s99_sort/s99_sort.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include // for auto_ptr -#include // for sort - -#include "../iucsamples.h" - -/** - * A comparison object for std::sort which compares two UnicodeStrings - * according to the Collator given. - * Note: UnicodeString is handled here, but UChar* could be handled similarly. - */ -class CollatorLessThan : public std::binary_function { -public: - /** - * @param coll the Collator to use. Aliased, not adopted. - * @param status error status from comparison functions. U_SUCCESS(status) should be TRUE on entry. Check the error value on exit from the sort function. NOTE: this reference is retained for the life of the CollatorLessThan object. - */ - CollatorLessThan(Collator &coll, UErrorCode &status) : fColl(coll), fStatus(status) {} - inline bool operator()(const UnicodeString& a, const UnicodeString& b) { - return (fColl.compare(a, b, fStatus) == UCOL_LESS); - } -private: - Collator &fColl; - UErrorCode &fStatus; -}; - -int main() { - // Locale to use - Danish. - Locale loc("da"); - // Input data. - UnicodeString A[] = { "tirsdag", "aaland", "abel", "zach" }; - const int N = sizeof(A) / sizeof(A[0]); - UErrorCode errorCode = U_ZERO_ERROR; - - // Setup. - std::auto_ptr coll(Collator::createInstance(loc, errorCode)); - - // Check that collator is OK. - std::cout << u_errorName(errorCode) << std::endl; - if(U_FAILURE(errorCode)) { - return 1; - } - - // The actual sort - std::sort(A, A + N, CollatorLessThan(*coll, errorCode)); - - if(U_FAILURE(errorCode)) { - std::cout << "Error comparing: " << u_errorName(errorCode) << std::endl; - return 1; - } - - // Print the resulting strings - for(int i=0;i mkdir tmp myapp -genrb -d myapp root.txt -genrb -d myapp es.txt +genrb -e utf-8 -d myapp root.txt +genrb -e utf-8 -d myapp es.txt pkgdata -v -T tmp -p myapp pkgdatain.txt -s . -d $(OutDir) diff --git a/iucsamples/c/data/es.txt b/iucsamples/c/data/es.txt index ef0527cc..8d0417ce 100644 --- a/iucsamples/c/data/es.txt +++ b/iucsamples/c/data/es.txt @@ -1,6 +1,6 @@ es { Aunt { "mi tía" } - table { "en la tabla" } + table { "sobre la mesa" } pen { "La pluma" } personPlaceThing { "{2} de {0} está {1}." } } diff --git a/icufacts/c/Makefile b/iucsamples/c/hellomsg/Makefile similarity index 51% rename from icufacts/c/Makefile rename to iucsamples/c/hellomsg/Makefile index a574a254..45932625 100644 --- a/icufacts/c/Makefile +++ b/iucsamples/c/hellomsg/Makefile @@ -1,12 +1,2 @@ # Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -all: - sh ./all.sh - -check: - sh ./check.sh - -clean: - sh ./clean.sh - - +include ../simple.mk diff --git a/iucsamples/c/hellomsg/hellomsg.cpp b/iucsamples/c/hellomsg/hellomsg.cpp new file mode 100644 index 00000000..844bf967 --- /dev/null +++ b/iucsamples/c/hellomsg/hellomsg.cpp @@ -0,0 +1,43 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include +#include +#include +#include +#include "../iucsamples.h" +using namespace icu; + +/** + * run with LC_ALL=es, LC_ALL=en etc. + */ + +int main() { + UErrorCode status = U_ZERO_ERROR; + LocalPointer + names(LocaleDisplayNames::createInstance(Locale::getDefault(), ULDN_DIALECT_NAMES)); + if(!names.isValid()) return 1; // hereafter: ASSERT_VALID(names); + UnicodeString world; + names->regionDisplayName("001", world); + + // New code, use a message + const int kArgCount=1; + Formattable arguments[kArgCount] = { world }; + UnicodeString argnames[kArgCount] = {"world"}; + FieldPosition fpos = 0; + + MessageFormat msg_en("Hello, {world}", + Locale("en"), status); + UnicodeString result_en; + msg_en.format(argnames, arguments, kArgCount, result_en, status); + ASSERT_OK(status); + std::cout << "en: " << result_en << std::endl; + + MessageFormat msg_es("¡Hola, {world}!", + Locale("es"), status); + UnicodeString result_es; + msg_es.format(argnames, arguments, kArgCount, result_es, status); + ASSERT_OK(status); + std::cout << "es: " << result_es << std::endl; + return 0; +} diff --git a/iucsamples/c/icupc.mk b/iucsamples/c/icupc.mk index ad6d274f..79c437e7 100644 --- a/iucsamples/c/icupc.mk +++ b/iucsamples/c/icupc.mk @@ -1,9 +1,22 @@ # Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. # pkg-config version -ICU_VER=$(shell pkg-config icu-io --modversion) -LDFLAGS+=$(shell pkg-config icu-io --libs) -CPPFLAGS+=$(shell pkg-config icu-io --cflags) +ICU_VER=$(shell $(ICUPKGCONFIG) icu-io --modversion) +LDFLAGS+=$(shell $(ICUPKGCONFIG) icu-io --libs) +CPPFLAGS+=$(shell $(ICUPKGCONFIG) icu-io --cflags) #INVOKE=$(shell icu-config --invoke) # assume can invoke from command line +CXX=c++ -std=c++11 + INVOKE= + +# make sure LDFLAGS come last due to library ordering + +%: %.c + $(CC) $(CPPFLAGS) -o $@ $< $(LDFLAGS) + +%: %.cc + $(CXX) $(CPPFLAGS) -o $@ $< $(LDFLAGS) + +%: %.cpp + $(CXX) $(CPPFLAGS) -o $@ $< $(LDFLAGS) diff --git a/iucsamples/c/iucsamples.h b/iucsamples/c/iucsamples.h index 2081f7f1..7e869a75 100644 --- a/iucsamples/c/iucsamples.h +++ b/iucsamples/c/iucsamples.h @@ -6,3 +6,8 @@ #define ASSERT_OK(x) if(U_FAILURE(x)) { fprintf(stderr,"%s:%d: ICU Failure %s\n", __FILE__, __LINE__, u_errorName(x)); } #endif + +#include +#if defined(__cplusplus) +using namespace icu; +#endif \ No newline at end of file diff --git a/iucsamples/c/readme.txt b/iucsamples/c/readme.txt index 910e9aae..0a079f7e 100644 --- a/iucsamples/c/readme.txt +++ b/iucsamples/c/readme.txt @@ -11,12 +11,16 @@ behavior on older ICUs with: ---- +Mac with homebrew: + +$ brew install icu4c pkg-config Windows Visual Studio: -Use the project file iucsamples.sln. -Set variable IcuDir to the root of your ICU build (containing bin, lib, include) -set PATH=%IcuDir%\bin;%PATH% +NOTE: currently broken, needs to be updated. +#Use the project file iucsamples.sln. +#Set variable IcuDir to the root of your ICU build (containing bin, lib, include) +#set PATH=%IcuDir%\bin;%PATH% UNIXes: see below. diff --git a/iucsamples/c/s09_test/s09_test.cpp b/iucsamples/c/s09_test/s09_test.c similarity index 64% rename from iucsamples/c/s09_test/s09_test.cpp rename to iucsamples/c/s09_test/s09_test.c index 15b77245..4343c537 100644 --- a/iucsamples/c/s09_test/s09_test.cpp +++ b/iucsamples/c/s09_test/s09_test.c @@ -2,15 +2,16 @@ #include #include "unicode/uclean.h" +#include "unicode/ustdio.h" int main() { UErrorCode status = U_ZERO_ERROR; u_init(&status); - printf("This is ICU %s!\n", U_ICU_VERSION); + u_printf_u(u"This is ICU %s! 😼\n", U_ICU_VERSION); if (U_SUCCESS(status)) { - printf("everything is OK\n"); + u_printf_u(u"everything is OK 🎉\n"); } else { - printf("error %s initializing.\n", u_errorName(status)); + u_printf_u(u"error 😕 %s initializing.\n", u_errorName(status)); return 1; } return 0; diff --git a/iucsamples/c/s09a_test/Makefile b/iucsamples/c/s09a_test/Makefile new file mode 100644 index 00000000..473517a2 --- /dev/null +++ b/iucsamples/c/s09a_test/Makefile @@ -0,0 +1,4 @@ +# © 2018 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html#License + +include ../simple.mk diff --git a/iucsamples/c/s09a_test/s09a_test.cpp b/iucsamples/c/s09a_test/s09a_test.cpp new file mode 100644 index 00000000..8cb79659 --- /dev/null +++ b/iucsamples/c/s09a_test/s09a_test.cpp @@ -0,0 +1,30 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License + +#include +#include +#include +#include +#include + +int main() { + icu::ErrorCode status; + icu::UnicodeString message(u"Welcome to ICU! 😼"); + std::cout << message << std::endl; + u_init(status); + if (status.isFailure()) { + std::cout + << icu::UnicodeString(u"error 😕 ") + << status.errorName() + << std::endl; + } else { + std::cout + << icu::UnicodeString(u"everything is OK 🎉") + << std::endl; + } + return status.get(); +} + +/** Emacs Local Variables: **/ +/** Emacs compile-command: "icurun s10_test_cpp.cpp" **/ +/** Emacs End: **/ diff --git a/iucsamples/c/s13_hello/s13_hello.cpp b/iucsamples/c/s13_hello/s13_hello.c similarity index 100% rename from iucsamples/c/s13_hello/s13_hello.cpp rename to iucsamples/c/s13_hello/s13_hello.c diff --git a/iucsamples/c/s13a_hello/Makefile b/iucsamples/c/s13a_hello/Makefile new file mode 100644 index 00000000..473517a2 --- /dev/null +++ b/iucsamples/c/s13a_hello/Makefile @@ -0,0 +1,4 @@ +# © 2018 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html#License + +include ../simple.mk diff --git a/iucsamples/c/s13a_hello/s13a_hello.cpp b/iucsamples/c/s13a_hello/s13a_hello.cpp new file mode 100644 index 00000000..da64530a --- /dev/null +++ b/iucsamples/c/s13a_hello/s13a_hello.cpp @@ -0,0 +1,25 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License + +#include +#include +#include +#include +#include + +#define ASSERT_OK(status) \ + if(status.isFailure()) { \ + puts(status.errorName()); \ + return 1; \ + } + +int main() { + icu::ErrorCode status; + icu::Locale locale("und_001"); + icu::UnicodeString world; + locale.getDisplayCountry(world); + ASSERT_OK(status); + + std::cout << "Hello, " << world << "!" << std::endl; + return 0; +} diff --git a/iucsamples/c/s23_brki/s23_brki.cpp b/iucsamples/c/s23_brki/s23_brki.cpp index 0903bd86..f8a30a8e 100644 --- a/iucsamples/c/s23_brki/s23_brki.cpp +++ b/iucsamples/c/s23_brki/s23_brki.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2010-2012 IBM Corporation and Others. All Rights Reserved. #include "../iucsamples.h" +#include #include #include #include @@ -10,25 +11,29 @@ void menu() { u_printf("[c]urrent(), [f]irst(), [l]ast(), [n]ext(), [p]revious() or [q]uit: "); } -int main() { +int main(int argc, const char** argv) { const char *locale = "en_US"; - UErrorCode status = U_ZERO_ERROR; - BreakIterator *characterIterator = BreakIterator::createCharacterInstance(locale, status); + icu::ErrorCode status; + BreakIterator *breakIterator = BreakIterator::createWordInstance(locale, status); ASSERT_OK(status); UnicodeString text; - text = "Text"; - characterIterator->setText(text); + if (argc <= 1) { + text = "Hello, world! How are you?"; + } else { + text = argv[1]; + } + breakIterator->setText(text); char buf[200]; menu(); while(!feof(stdin) && fgets(buf,200,stdin) && buf[0]!='q') { switch(buf[0]) { - case 'c': u_printf("current() == %d\n", characterIterator->current()); break; - case 'f': u_printf("first()==%d\n", characterIterator->first()); break; - case 'l': u_printf("last()==%d\n", characterIterator->last()); break; - case 'n': u_printf("next()==%d\n", characterIterator->next()); break; - case 'p': u_printf("previous()==%d\n", characterIterator->previous()); break; + case 'c': u_printf("current() == %d\n", breakIterator->current()); break; + case 'f': u_printf("first()==%d\n", breakIterator->first()); break; + case 'l': u_printf("last()==%d\n", breakIterator->last()); break; + case 'n': u_printf("next()==%d\n", breakIterator->next()); break; + case 'p': u_printf("previous()==%d\n", breakIterator->previous()); break; default: u_printf(" ( didn't understand \"%c\" )\n", buf[0]); } menu(); diff --git a/iucsamples/c/s27_brkl/s27_brkl.cpp b/iucsamples/c/s27_brkl/s27_brkl.cpp index e2cf0570..6fa93dfc 100644 --- a/iucsamples/c/s27_brkl/s27_brkl.cpp +++ b/iucsamples/c/s27_brkl/s27_brkl.cpp @@ -3,6 +3,7 @@ #include "../iucsamples.h" #include #include +#include #include int32_t previousBreak(BreakIterator *breakIterator, UnicodeString &text, diff --git a/iucsamples/c/s34_coll/s34_coll.cpp b/iucsamples/c/s34_coll/s34_coll.cpp index cb8b443e..a5c4d11a 100644 --- a/iucsamples/c/s34_coll/s34_coll.cpp +++ b/iucsamples/c/s34_coll/s34_coll.cpp @@ -67,7 +67,7 @@ void s36_cppsort() { if(U_SUCCESS(status)) { for(i=listSize-1; i>=1; i--) { for(j=0; jcompare(s[j], s[j+1]) == UCOL_LESS) { + if(coll->compare(s[j], s[j+1], status) == UCOL_LESS) { swap(s[j], s[j+1]); } } diff --git a/iucsamples/c/s88_units/Makefile b/iucsamples/c/s88_units/Makefile new file mode 100644 index 00000000..473517a2 --- /dev/null +++ b/iucsamples/c/s88_units/Makefile @@ -0,0 +1,4 @@ +# © 2018 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html#License + +include ../simple.mk diff --git a/iucsamples/c/s88_units/s88_units.cpp b/iucsamples/c/s88_units/s88_units.cpp new file mode 100644 index 00000000..09770c71 --- /dev/null +++ b/iucsamples/c/s88_units/s88_units.cpp @@ -0,0 +1,46 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License + +#include +#include +#include +#include +#include +#include +#include + +#define ASSERT_OK(status) \ + if(status.isFailure()) { \ + printf("Error on line %d:\n", __LINE__); \ + puts(status.errorName()); \ + return 1; \ + } + +icu::UnicodeString run(const char16_t* pattern, double quantity) { + icu::ErrorCode status; + + icu::MessageFormat mfmt(pattern, status); + ASSERT_OK(status); + icu::UnicodeString result; + icu::Formattable args[] = {quantity}; + mfmt.format({args, 1}, result, status); + ASSERT_OK(status); + return result; +} + +int main() { + const char16_t* pattern1 = u"The room measures " + "{0, plural, one{1 meter} other{# meters}}" + " wide."; + const char16_t* pattern2 = u"The room measures " + "{0, number, ::measure-unit/length-meter unit-width-full-name}" + " wide."; + + std::cout << run(pattern1, 1) << std::endl; + std::cout << run(pattern1, 5) << std::endl; + std::cout << run(pattern2, 1) << std::endl; + std::cout << run(pattern2, 5) << std::endl; + + u_cleanup(); + return 0; +} diff --git a/iucsamples/c/s99_compact/Makefile b/iucsamples/c/s99_compact/Makefile new file mode 100644 index 00000000..473517a2 --- /dev/null +++ b/iucsamples/c/s99_compact/Makefile @@ -0,0 +1,4 @@ +# © 2018 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html#License + +include ../simple.mk diff --git a/iucsamples/c/s99_compact/s99_compact.cpp b/iucsamples/c/s99_compact/s99_compact.cpp new file mode 100644 index 00000000..4de66964 --- /dev/null +++ b/iucsamples/c/s99_compact/s99_compact.cpp @@ -0,0 +1,65 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License + +#include +#include +#include +#include +#include +#include +#include +#include + +#if U_ICU_VERSION_MAJOR_NUM < 62 +# error for ICU before 62.x, change toString(status) to toString() +#endif + + +#define ASSERT_OK(status) \ + if(status.isFailure()) { \ + printf("Error on line %d:\n", __LINE__); \ + puts(status.errorName()); \ + return 1; \ + } + +int main() { + icu::ErrorCode status; + const int32_t quantity = 987654321; + + // Create NumberFormatter + icu::number::LocalizedNumberFormatter lnf = icu::number::NumberFormatter::with() + .notation(icu::number::Notation::compactShort()) + .locale("en-us"); + + // Check NumberFormatter (optional: error also set in format method) + lnf.copyErrorTo(status); + ASSERT_OK(status); + + // Run NumberFormatter + std::cout + << lnf.formatDouble(quantity, status).toString(status) + << std::endl; + + // NumberFormatter all in one line + std::cout + << icu::number::NumberFormatter::with() + .notation(icu::number::Notation::compactShort()) + .locale("en-us") + .formatDouble(quantity, status) + .toString(status) + << std::endl; + + // Create MessageFormat + icu::MessageFormat mfmt(u"{0, number, ::compact-short}", status); + ASSERT_OK(status); + + // Run MessageFormat + icu::UnicodeString result; + icu::Formattable args[] = {quantity}; + mfmt.format({args, 1}, result, status); + ASSERT_OK(status); + std::cout << result << std::endl; + + u_cleanup(); + return 0; +} diff --git a/iucsamples/j/Makefile b/iucsamples/j/Makefile deleted file mode 100644 index e9ab2136..00000000 --- a/iucsamples/j/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -ALLJAVA=$(shell ls *.java) -ALLCLASS=$(ALLJAVA:%.java=%.class) -ALLAPP=$(ALLJAVA:%.java=%) -CLASSPATH=.:$(ICU4J) - -# create a 'local.mk' with a line like this: -## ICU4J=/Users/srl/Downloads/icu4j-4_4.jar -include local.mk - -all: $(ALLCLASS) - -check: all - for class in $(ALLAPP); do echo ____ $$class ____; java -classpath $(CLASSPATH):. $$class; echo; done - -check-%: %.class - echo running %* - java -classpath $(CLASSPATH) $* - -%.class: %.java - javac -classpath $(CLASSPATH) $^ - -clean: - -rm *.class - -rm -f myapp.lst - -CDATA=../c/data - -# -# This target rebuilds data from C -# -rebuild-data: $(CDATA)/myapp.dat - -rm -rf data/myapp/*.res - -mkdir -p data/myapp - icupkg -l $(CDATA)/myapp.dat > myapp.lst - icupkg -x myapp.lst -tb -d data $(CDATA)/myapp.dat - -rm -f myapp.lst - -$(CDATA)/myapp.dat: - make -C $(CDATA) clean all - -local.mk: - $(error please read the readme.txt and create local.mk) diff --git a/iucsamples/j/data/myapp/es.res b/iucsamples/j/data/myapp/es.res deleted file mode 100644 index ee7a31d1c649165bb45bc2a8cc82b584646a6b8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 224 zcmX|+I|{-;7=%A1prwMXu#H#<@o@vKErNJ~L>CRLYcQKiypTt-^8nt#Nr?V1!_54{ zJ}|E-Bk0g&XUk0&=}6R00xQX$Fc9Jvzec>Sd?2KmvlP|~xAN)}mmci?ocojNT*xs5 zKBRJ6v7x|GX;UW_uf#QZ5NC~syKa7Hb5z5~EgEMjb=JE{mP+auMRGIdO!SRDV}{TF Fd;!80Cs6Ru?~1zHKVP|{-3g%mI3kvxqf)E6c*U*0T& z`6Mi1Ld3=TQ-pG?Yn&W5iZf{;rKA3hH0xa;6lG)StdkzTb$L_V?6s=hU3EGvPJZTz wA)^-saVs}UmG(a`C~1^oV9$$0$7?fi6dCG~4x+7EvEEX4teNWjE9P&_7c$WxV*mgE diff --git a/iucsamples/j/icu2work/.gitignore b/iucsamples/j/icu2work/.gitignore new file mode 100644 index 00000000..2fe47d41 --- /dev/null +++ b/iucsamples/j/icu2work/.gitignore @@ -0,0 +1,7 @@ +/target/ +.project +.idea +.settings/ +.idea/ +.classpath +*.iml diff --git a/iucsamples/j/icu2work/pom.xml b/iucsamples/j/icu2work/pom.xml new file mode 100644 index 00000000..bf9a4ae2 --- /dev/null +++ b/iucsamples/j/icu2work/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.icu-project.sample.icu2work + icu2work + 1.0-iuc43-SNAPSHOT + jar + + icu2work + http://icu-project.org + + + Unicode/ICU License + http://source.icu-project.org/repos/icu/trunk/icu4j/main/shared/licenses/LICENSE + repo + + + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M1 + + + enforce-java + + enforce + + + + + [1.8,) + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.2 + + 1.8 + 1.8 + true + true + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.0-M1 + + + attach-javadocs + + jar + + + + + + + + + + + junit + junit + 4.11 + test + + + com.ibm.icu + icu4j + 65.1 + + + diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/.gitignore b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/.gitignore new file mode 100644 index 00000000..d5bfebdb --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/.gitignore @@ -0,0 +1,4 @@ +/BadMessage.class +/CollateMessage.class +/GoodMessage.class +/Hello.class diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/BadMessage.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/BadMessage.java new file mode 100644 index 00000000..56de0cb1 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/BadMessage.java @@ -0,0 +1,26 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +package com.ibm.us.srloomis.demo.icu2work; + +import com.ibm.icu.text.MessageFormat; +import com.ibm.us.srloomis.demo.icu2work.impl.PopulationData; + +import java.util.*; + +public class BadMessage { + public static void main(String args[]) { + final Locale locale = Locale.getDefault(); + ResourceBundle rb = ResourceBundle.getBundle(BadMessage.class.getName()); + String popmsg = rb.getString("population"); + System.out.println("Message: " + popmsg); + + for(final PopulationData.TerritoryEntry entry : PopulationData.getTerritoryEntries(locale)) { + MessageFormat m = new MessageFormat(popmsg, locale); + Map msgArgs = new HashMap(); + msgArgs.put("territory", entry.territoryName()); + msgArgs.put("population", entry.population()); + System.out.println(m.format(msgArgs)); + } + } +} diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/CollateMessage.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/CollateMessage.java new file mode 100644 index 00000000..f9c19fe9 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/CollateMessage.java @@ -0,0 +1,29 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +package com.ibm.us.srloomis.demo.icu2work; + +import com.ibm.icu.text.Collator; +import com.ibm.icu.text.MessageFormat; +import com.ibm.us.srloomis.demo.icu2work.impl.PopulationData; + +import java.util.*; + +public class CollateMessage { + public static void main(String args[]) { + final Locale locale = Locale.getDefault(); + ResourceBundle rb = ResourceBundle.getBundle(GoodMessage.class.getName()); + String popmsg = rb.getString("population"); + System.out.println("Message: " + popmsg); + + Collator col = Collator.getInstance(locale); + for(final PopulationData.TerritoryEntry entry : PopulationData.getTerritoryEntries(locale, + new TreeSet<>((o1, o2) -> col.compare(o1.territoryName(), o2.territoryName())))) { + MessageFormat m = new MessageFormat(popmsg, locale); + Map msgArgs = new HashMap(); + msgArgs.put("territory", entry.territoryName()); + msgArgs.put("population", entry.population()); + System.out.println(m.format(msgArgs)); + } + } +} diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/GoodMessage.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/GoodMessage.java new file mode 100644 index 00000000..ba8bebe7 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/GoodMessage.java @@ -0,0 +1,29 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +package com.ibm.us.srloomis.demo.icu2work; + +import com.ibm.icu.text.MessageFormat; +import com.ibm.us.srloomis.demo.icu2work.impl.PopulationData; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; + +public class GoodMessage { + public static void main(String args[]) { + final Locale locale = Locale.getDefault(); + ResourceBundle rb = ResourceBundle.getBundle(GoodMessage.class.getName()); + String popmsg = rb.getString("population"); + System.out.println("Message: " + popmsg); + + for(final PopulationData.TerritoryEntry entry : PopulationData.getTerritoryEntries(locale)) { + MessageFormat m = new MessageFormat(popmsg, locale); + Map msgArgs = new HashMap(); + msgArgs.put("territory", entry.territoryName()); + msgArgs.put("population", entry.population()); + System.out.println(m.format(msgArgs)); + } + } +} diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/Hello.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/Hello.java new file mode 100644 index 00000000..753859f6 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/Hello.java @@ -0,0 +1,27 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +package com.ibm.us.srloomis.demo.icu2work; + +import com.ibm.icu.text.LocaleDisplayNames; +import com.ibm.icu.util.ULocale; + +import java.util.Locale; + +/** + * Hello world! + * + */ +public class Hello +{ + public static void main( String[] args ) + { + //Locale locale = Locale.getDefault(); + Locale locale = Locale.forLanguageTag("es"); + String world = LocaleDisplayNames + .getInstance(ULocale.forLocale(locale)) + .regionDisplayName("001"); + System.out.println("Hello, " + world + "\u2603"); + } + +} diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/.gitignore b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/.gitignore new file mode 100644 index 00000000..58dba425 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/.gitignore @@ -0,0 +1,3 @@ +/PopulationData$TerritoryEntry.class +/PopulationData.class +/SupplementalUtilities.class diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/PopulationData.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/PopulationData.java new file mode 100644 index 00000000..315c28d3 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/PopulationData.java @@ -0,0 +1,84 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License +/* + ******************************************************************************* + * Copyright (C) 2013-2014, International Business Machines Corporation and * + * others. All Rights Reserved. * + ******************************************************************************* + */ +package com.ibm.us.srloomis.demo.icu2work.impl; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; +import java.util.TreeSet; + +import com.ibm.icu.text.NumberFormat; +import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.UResourceBundle; +import com.ibm.icu.util.UResourceBundleIterator; + +/** + * @author srl + * + */ +public class PopulationData { + /** + * Entry in the population list + */ + public static class TerritoryEntry implements Comparable { + private String territoryName; + private double population; + public TerritoryEntry(String displayCountry, double population) { + this.territoryName = displayCountry; + this.population = population; + } + public String territoryName() { + return territoryName; + } + public double population() { + return population; + } + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(TerritoryEntry o) { + int rc = 0; + if (rc==0) rc = territoryName.compareTo(o.territoryName()); + if (rc==0) rc = ((Double)population).compareTo(o.population()); + return rc; + } + }; + public static Set getTerritoryEntries(Locale loc) { + return getTerritoryEntries(loc, null); + } + public static Set getTerritoryEntries(Locale loc, Set entries) { + if(entries == null) entries = new TreeSet(); + // Note: format of supplementalData is NOT STATIC and may change. It is internal to ICU! + UResourceBundle suppData = SupplementalUtilities.getICUSupplementalData(); + UResourceBundle territoryInfo = suppData.get("territoryInfo"); +// int nTerr = territoryInfo.getSize(); + for(UResourceBundleIterator iter = territoryInfo.getIterator();iter.hasNext();) { + UResourceBundle rawEntry= iter.next(); + UResourceBundle territoryF = rawEntry.get("territoryF"); + int vec[] = territoryF.getIntVector(); + + // now we have the entry + // territoryF = { gdp, literacy, population } + String terrID = rawEntry.getKey(); + ULocale territory = new ULocale("und", terrID); + entries.add(new TerritoryEntry(territory.getDisplayCountry(ULocale.forLocale(loc)), SupplementalUtilities.ldml2d(vec[2]))); + } + return entries; + } + + public static void main(String... args) { + NumberFormat nf = NumberFormat.getInstance(); + System.out.println("Loading population/territory data from CLDR"); + Set territoryEntries = getTerritoryEntries(Locale.getDefault(), new HashSet()); + System.out.println(".. count="+ nf.format(territoryEntries.size())); + for(TerritoryEntry te : territoryEntries) { + System.out.println(" "+ te.territoryName() + " = " + nf.format(te.population())); + } + } +} diff --git a/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/SupplementalUtilities.java b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/SupplementalUtilities.java new file mode 100644 index 00000000..476fdea9 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/java/com/ibm/us/srloomis/demo/icu2work/impl/SupplementalUtilities.java @@ -0,0 +1,84 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html#License +/* + ******************************************************************************* + * Copyright (C) 2013-2016, International Business Machines Corporation and + * others. All Rights Reserved. + ******************************************************************************* + */ +package com.ibm.us.srloomis.demo.icu2work.impl; + +import com.ibm.icu.impl.ICUData; +import com.ibm.icu.impl.ICUResourceBundle; +import com.ibm.icu.util.UResourceBundle; + +/** + * @author srl + * + */ +public class SupplementalUtilities { + /** + * Convert LDML2ICUConverter format floating point (territoryF, etc) + * into double. + * See: SupplementalMapper.java + * @param n input number, such as -48123456 + * @return double value, such as -123.456 + * @internal + */ + public static double ldml2d(int n) { + if(n == 0) { + return 0.; + } + boolean neg = false; + if(n < 0) { + n = -n; + neg = true; + } + int exp = (n/1000000); + n -= (exp * 1000000); + int sexp = exp - 50; // signed exponent + double d = n; + d = d * Math.pow(10, (sexp-5)); // -5 because 50 isn't quite right.. + if(neg) { + d = -d; + } + return d; + } + + /** Test function */ + public static void main(String... args) { + + System.out.println("Testingldml2d"); + int junk[] = { + 49990000, // 99% + 48680000, // 6.8% + 57344400, // ? + 52940000, // ? + 0, + -48123456, // gets -0.012346 not -123.456 + -52123456, // this one gets -123.456 + 46100000, + 63146600 + }; + + for(int i=0;i " + Double.toString(ldml2d(junk[i]))); + } + + System.out.println(); + System.out.println("Testing getICUSupplementalData"); + System.out.println("SupplementalData has " + getICUSupplementalData().getSize() + " size. (nonzero is good!)" ); + } + + /** + * Open ICU supplemental data + * @return the bundle + */ + public static UResourceBundle getICUSupplementalData() { + UResourceBundle suppData = UResourceBundle.getBundleInstance( + ICUData.ICU_BASE_NAME, + "supplementalData", + ICUResourceBundle.ICU_DATA_CLASS_LOADER); + return suppData; + } +} diff --git a/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/BadMessage.properties b/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/BadMessage.properties new file mode 100644 index 00000000..515e2551 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/BadMessage.properties @@ -0,0 +1,3 @@ +# (c) 2016 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html +population=The territory of {territory} has {population} persons. \ No newline at end of file diff --git a/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/GoodMessage.properties b/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/GoodMessage.properties new file mode 100644 index 00000000..1d045415 --- /dev/null +++ b/iucsamples/j/icu2work/src/main/resources/com/ibm/us/srloomis/demo/icu2work/GoodMessage.properties @@ -0,0 +1,3 @@ +# (c) 2016 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html +population={population, plural, one{The territory of {territory} has # person} other{The territory of {territory} has # persons}} \ No newline at end of file diff --git a/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/.gitignore b/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/.gitignore new file mode 100644 index 00000000..f303afdd --- /dev/null +++ b/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/.gitignore @@ -0,0 +1,2 @@ +/AppTest$AllApps.class +/AppTest.class diff --git a/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/AppTest.java b/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/AppTest.java new file mode 100644 index 00000000..7296bb65 --- /dev/null +++ b/iucsamples/j/icu2work/src/test/java/com/ibm/us/srloomis/demo/icu2work/AppTest.java @@ -0,0 +1,35 @@ +package com.ibm.us.srloomis.demo.icu2work; + +import org.junit.Test; + +import java.lang.reflect.Method; + +public class AppTest +{ + final static private String[] NO_ARGS = new String[0]; + + enum AllApps { + Hello, + BadMessage + }; + /** + * Rigourous Test :-) + */ + @Test + public void testApp() + { + for(AllApps a : AllApps.values()) { + final String app = a.name(); + System.out.println("** " + app); + final String className = getClass().getPackage().getName()+"."+app; + try { + Class c = Class.forName(className); + Method main = c.getMethod("main", String[].class); + main.invoke(null, (Object) NO_ARGS); + } catch (Throwable e) { + System.out.println("Err: " + className); + e.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/iucsamples/j/readme.txt b/iucsamples/j/readme.txt deleted file mode 100644 index 3405a0df..00000000 --- a/iucsamples/j/readme.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2011 IBM Corporation and Others. All Rights Reserved - -** To use from the command line: (UNIX) -* create local.mk with "ICU4J=/Users/srl/Downloads/icu4j.jar" then 'make check' should run each test. - -** Otherwise, you can compile as follows given some "icu4j.jar" - javac -classpath icu4j.jar s49.java - java -classpath icu4j.jar:. s49 - -** Otherwise, to use from Eclipse, import the 'j' directory as a Java project ( icu-iucsamples-j ) -and set the ICU_UTILITIES User Class entry to contain icu4j.jar - - ----- - -Note that s58 requires the "data" directory to be in the current working path. diff --git a/iucsamples/j/s49.java b/iucsamples/j/s49.java deleted file mode 100644 index de144137..00000000 --- a/iucsamples/j/s49.java +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2010 IBM Corporation and Others. All Rights Reserved. - -import com.ibm.icu.util.ULocale; -import com.ibm.icu.util.VersionInfo; -public class s49 { - public static void main(String[] args) { - System.out.println("Hello, " + new ULocale("und_001") - .getDisplayCountry(ULocale.GERMAN) - + "! ICU " + VersionInfo.ICU_VERSION); - } -} diff --git a/iucsamples/j/s52.java b/iucsamples/j/s52.java deleted file mode 100644 index 2aa6f66a..00000000 --- a/iucsamples/j/s52.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2010-2012 IBM Corporation and Others. All Rights Reserved. -import java.util.TreeSet; - -import com.ibm.icu.text.Collator; -import com.ibm.icu.util.ULocale; - -public class s52 { - public static void collation() { - ULocale locale = new ULocale("fr"); - Collator coll = Collator.getInstance(locale); - // do useful things with the collator - - String s1 = "World"; - String s2 = "Hello"; - - System.out.println("Comparing " + s1 + " / " + s2 + " = " - + coll.compare(s1, s2)); - - TreeSet set = new TreeSet(coll); - set.add(s1); - set.add(s2); - for (String s : set) { - System.out.println(" " + s); - } - } - - public static void main(String args[]) { - collation(); - } -} diff --git a/iucsamples/j/s56.java b/iucsamples/j/s56.java deleted file mode 100644 index 4c034672..00000000 --- a/iucsamples/j/s56.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2010-2012 IBM Corporation and Others. All Rights Reserved. -import java.util.TreeMap; - -import com.ibm.icu.text.CollationKey; -import com.ibm.icu.text.Collator; -import com.ibm.icu.text.RawCollationKey; -import com.ibm.icu.util.ULocale; - -public class s56 { - public static void collationKey() { - ULocale locale = new ULocale("fr"); - Collator coll = Collator.getInstance(locale); - - String strs[] = { "bad", "baz", "Bat", "BAD", "bat" }; - - TreeMap rawMap = new TreeMap(); - TreeMap keyMap = new TreeMap(); - for(String s : strs) { - - RawCollationKey rk = coll.getRawCollationKey(s, null); - rawMap.put(rk,s); - - System.out.println("str " + s + ", raw: " + rk.toString()); - - - CollationKey key = coll.getCollationKey(s); - keyMap.put(key, s); - } - - System.out.println("in raw map order: " ) ; - for(String s : rawMap.values()) { - System.out.println("\t"+s); - } - System.out.println("in key map order: " ) ; - for(String s : keyMap.values()) { - System.out.println("\t"+s); - } - - RawCollationKey bazKey = coll.getRawCollationKey("baz",null); - System.out.println("I want 'baz', key " + bazKey); - System.out.println(" -> " + rawMap.get(bazKey)); - } - - public static void main(String args[]) { - collationKey(); - System.err.println("collationKey"); - } -} diff --git a/iucsamples/j/s58.java b/iucsamples/j/s58.java deleted file mode 100644 index d687c01c..00000000 --- a/iucsamples/j/s58.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2010-2012 IBM Corporation and Others. All Rights Reserved. -import com.ibm.icu.text.MessageFormat; -import com.ibm.icu.util.ULocale; -import com.ibm.icu.util.UResourceBundle; - -public class s58 { - - public static void msgFormat(ULocale loc) { - UResourceBundle resourceBundle = UResourceBundle.getBundleInstance("data/myapp", loc); - String person = resourceBundle.getString("Aunt"); // e.g. "My Aunt" - String place = resourceBundle.getString("table"); // e.g. "on the table" - String thing = resourceBundle.getString("pen"); // e.g. "pen" - Object arguments[] = {person, place, thing}; - String pattern = resourceBundle.getString("personPlaceThing"); - MessageFormat msgFmt = new MessageFormat(pattern); - String message = msgFmt.format(arguments); - System.out.println(loc + ": " + message); - } - - public static void main(String args[]) { - { - String locs[] = { "es", "root" }; - for(String loc : locs) { - msgFormat(new ULocale(loc)); - } - } - System.err.println("messageFormat"); - } -} diff --git a/iucsamples/readme.txt b/iucsamples/readme.txt index b361b5f2..cd28cb92 100644 --- a/iucsamples/readme.txt +++ b/iucsamples/readme.txt @@ -1,10 +1,10 @@ # Copyright (c) 2010-2012 IBM Corporation and Others. All Rights Reserved. -IUC 35 Samples +IUC 43 Samples This source package is provided as a convenience, and is not fully 'productized'. -ICU 49 or 50 recommended. +ICU 64+ recommended. See the readme.txt in the C and J directories.