From e5786f530f9555469c01435f86039b06aa53feba Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner
Date: Mon, 20 Apr 2009 18:13:48 +0000
Subject: new build system: build icu libs and xetex plus misc updates
git-svn-id: svn://tug.org/texlive/trunk@12759 c570f23f-e606-0410-a88d-b1316a301751
---
Build/source/libs/icu/icu-xetex/common/Makefile.in | 203 +
Build/source/libs/icu/icu-xetex/common/bmpset.cpp | 723 +++
Build/source/libs/icu/icu-xetex/common/bmpset.h | 161 +
Build/source/libs/icu/icu-xetex/common/brkeng.cpp | 290 ++
Build/source/libs/icu/icu-xetex/common/brkeng.h | 292 ++
Build/source/libs/icu/icu-xetex/common/brkiter.cpp | 454 ++
Build/source/libs/icu/icu-xetex/common/caniter.cpp | 611 +++
.../source/libs/icu/icu-xetex/common/chariter.cpp | 96 +
Build/source/libs/icu/icu-xetex/common/charstr.h | 88 +
Build/source/libs/icu/icu-xetex/common/cmemory.c | 124 +
Build/source/libs/icu/icu-xetex/common/cmemory.h | 82 +
Build/source/libs/icu/icu-xetex/common/common.rc | 108 +
.../source/libs/icu/icu-xetex/common/common.vcproj | 2588 ++++++++++
Build/source/libs/icu/icu-xetex/common/cpputils.h | 84 +
Build/source/libs/icu/icu-xetex/common/cstring.c | 328 ++
Build/source/libs/icu/icu-xetex/common/cstring.h | 120 +
Build/source/libs/icu/icu-xetex/common/cwchar.c | 53 +
Build/source/libs/icu/icu-xetex/common/cwchar.h | 56 +
Build/source/libs/icu/icu-xetex/common/dictbe.cpp | 426 ++
Build/source/libs/icu/icu-xetex/common/dictbe.h | 193 +
Build/source/libs/icu/icu-xetex/common/hash.h | 207 +
Build/source/libs/icu/icu-xetex/common/icucfg.h.in | 61 +
Build/source/libs/icu/icu-xetex/common/localsvc.h | 25 +
.../source/libs/icu/icu-xetex/common/locbased.cpp | 46 +
Build/source/libs/icu/icu-xetex/common/locbased.h | 97 +
Build/source/libs/icu/icu-xetex/common/locid.cpp | 1330 ++++++
Build/source/libs/icu/icu-xetex/common/locmap.c | 893 ++++
Build/source/libs/icu/icu-xetex/common/locmap.h | 37 +
Build/source/libs/icu/icu-xetex/common/locutil.cpp | 267 ++
Build/source/libs/icu/icu-xetex/common/locutil.h | 37 +
Build/source/libs/icu/icu-xetex/common/msvcres.h | 20 +
Build/source/libs/icu/icu-xetex/common/mutex.h | 85 +
Build/source/libs/icu/icu-xetex/common/normlzr.cpp | 611 +++
.../source/libs/icu/icu-xetex/common/parsepos.cpp | 21 +
.../source/libs/icu/icu-xetex/common/propname.cpp | 758 +++
Build/source/libs/icu/icu-xetex/common/propname.h | 515 ++
Build/source/libs/icu/icu-xetex/common/punycode.c | 580 +++
Build/source/libs/icu/icu-xetex/common/punycode.h | 118 +
Build/source/libs/icu/icu-xetex/common/putil.c | 1675 +++++++
Build/source/libs/icu/icu-xetex/common/putilimp.h | 277 ++
Build/source/libs/icu/icu-xetex/common/rbbi.cpp | 1832 ++++++++
Build/source/libs/icu/icu-xetex/common/rbbicst.pl | 453 ++
.../source/libs/icu/icu-xetex/common/rbbidata.cpp | 444 ++
Build/source/libs/icu/icu-xetex/common/rbbidata.h | 193 +
.../source/libs/icu/icu-xetex/common/rbbinode.cpp | 355 ++
Build/source/libs/icu/icu-xetex/common/rbbinode.h | 118 +
Build/source/libs/icu/icu-xetex/common/rbbirb.cpp | 312 ++
Build/source/libs/icu/icu-xetex/common/rbbirb.h | 211 +
Build/source/libs/icu/icu-xetex/common/rbbirpt.h | 275 ++
Build/source/libs/icu/icu-xetex/common/rbbirpt.txt | 315 ++
.../source/libs/icu/icu-xetex/common/rbbiscan.cpp | 1193 +++++
Build/source/libs/icu/icu-xetex/common/rbbiscan.h | 160 +
.../source/libs/icu/icu-xetex/common/rbbisetb.cpp | 684 +++
Build/source/libs/icu/icu-xetex/common/rbbisetb.h | 130 +
.../source/libs/icu/icu-xetex/common/rbbistbl.cpp | 269 ++
.../source/libs/icu/icu-xetex/common/rbbitblb.cpp | 1232 +++++
Build/source/libs/icu/icu-xetex/common/rbbitblb.h | 127 +
Build/source/libs/icu/icu-xetex/common/resbund.cpp | 396 ++
.../libs/icu/icu-xetex/common/resbund_cnv.cpp | 55 +
.../source/libs/icu/icu-xetex/common/ruleiter.cpp | 160 +
Build/source/libs/icu/icu-xetex/common/ruleiter.h | 232 +
.../source/libs/icu/icu-xetex/common/schriter.cpp | 115 +
Build/source/libs/icu/icu-xetex/common/serv.cpp | 974 ++++
Build/source/libs/icu/icu-xetex/common/serv.h | 996 ++++
Build/source/libs/icu/icu-xetex/common/servlk.cpp | 187 +
Build/source/libs/icu/icu-xetex/common/servlkf.cpp | 151 +
Build/source/libs/icu/icu-xetex/common/servloc.h | 550 +++
Build/source/libs/icu/icu-xetex/common/servls.cpp | 297 ++
.../source/libs/icu/icu-xetex/common/servnotf.cpp | 118 +
Build/source/libs/icu/icu-xetex/common/servnotf.h | 124 +
Build/source/libs/icu/icu-xetex/common/servrbf.cpp | 94 +
.../source/libs/icu/icu-xetex/common/servslkf.cpp | 122 +
Build/source/libs/icu/icu-xetex/common/sprpimpl.h | 129 +
.../source/libs/icu/icu-xetex/common/triedict.cpp | 1407 ++++++
Build/source/libs/icu/icu-xetex/common/triedict.h | 346 ++
Build/source/libs/icu/icu-xetex/common/uarrsort.c | 236 +
Build/source/libs/icu/icu-xetex/common/uarrsort.h | 84 +
Build/source/libs/icu/icu-xetex/common/uassert.h | 32 +
Build/source/libs/icu/icu-xetex/common/ubidi.c | 2224 +++++++++
.../source/libs/icu/icu-xetex/common/ubidi_props.c | 520 ++
.../source/libs/icu/icu-xetex/common/ubidi_props.h | 160 +
.../libs/icu/icu-xetex/common/ubidi_props_data.c | 549 +++
Build/source/libs/icu/icu-xetex/common/ubidiimp.h | 385 ++
Build/source/libs/icu/icu-xetex/common/ubidiln.c | 1346 ++++++
Build/source/libs/icu/icu-xetex/common/ubidiwrt.c | 630 +++
Build/source/libs/icu/icu-xetex/common/ubrk.cpp | 293 ++
Build/source/libs/icu/icu-xetex/common/ubrkimpl.h | 13 +
Build/source/libs/icu/icu-xetex/common/ucase.c | 1599 +++++++
Build/source/libs/icu/icu-xetex/common/ucase.h | 376 ++
.../libs/icu/icu-xetex/common/ucase_props_data.c | 601 +++
Build/source/libs/icu/icu-xetex/common/ucasemap.c | 563 +++
Build/source/libs/icu/icu-xetex/common/ucat.c | 76 +
Build/source/libs/icu/icu-xetex/common/uchar.c | 979 ++++
.../libs/icu/icu-xetex/common/uchar_props_data.c | 2155 +++++++++
.../source/libs/icu/icu-xetex/common/uchriter.cpp | 363 ++
Build/source/libs/icu/icu-xetex/common/ucln.h | 68 +
Build/source/libs/icu/icu-xetex/common/ucln_cmn.c | 74 +
Build/source/libs/icu/icu-xetex/common/ucln_cmn.h | 63 +
Build/source/libs/icu/icu-xetex/common/ucmndata.c | 300 ++
Build/source/libs/icu/icu-xetex/common/ucmndata.h | 109 +
Build/source/libs/icu/icu-xetex/common/ucnv.c | 2888 ++++++++++++
Build/source/libs/icu/icu-xetex/common/ucnv2022.c | 3463 ++++++++++++++
Build/source/libs/icu/icu-xetex/common/ucnv_bld.c | 1583 +++++++
Build/source/libs/icu/icu-xetex/common/ucnv_bld.h | 281 ++
Build/source/libs/icu/icu-xetex/common/ucnv_cb.c | 259 +
Build/source/libs/icu/icu-xetex/common/ucnv_cnv.c | 174 +
Build/source/libs/icu/icu-xetex/common/ucnv_cnv.h | 303 ++
Build/source/libs/icu/icu-xetex/common/ucnv_err.c | 396 ++
Build/source/libs/icu/icu-xetex/common/ucnv_ext.c | 1088 +++++
Build/source/libs/icu/icu-xetex/common/ucnv_ext.h | 463 ++
Build/source/libs/icu/icu-xetex/common/ucnv_imp.h | 95 +
Build/source/libs/icu/icu-xetex/common/ucnv_io.c | 1341 ++++++
Build/source/libs/icu/icu-xetex/common/ucnv_io.h | 125 +
Build/source/libs/icu/icu-xetex/common/ucnv_lmb.c | 1281 +++++
Build/source/libs/icu/icu-xetex/common/ucnv_set.c | 67 +
Build/source/libs/icu/icu-xetex/common/ucnv_u16.c | 1372 ++++++
Build/source/libs/icu/icu-xetex/common/ucnv_u32.c | 1250 +++++
Build/source/libs/icu/icu-xetex/common/ucnv_u7.c | 1459 ++++++
Build/source/libs/icu/icu-xetex/common/ucnv_u8.c | 1084 +++++
Build/source/libs/icu/icu-xetex/common/ucnvbocu.c | 1393 ++++++
Build/source/libs/icu/icu-xetex/common/ucnvdisp.c | 86 +
Build/source/libs/icu/icu-xetex/common/ucnvhz.c | 591 +++
Build/source/libs/icu/icu-xetex/common/ucnvisci.c | 1469 ++++++
Build/source/libs/icu/icu-xetex/common/ucnvlat1.c | 743 +++
Build/source/libs/icu/icu-xetex/common/ucnvmbcs.c | 4946 ++++++++++++++++++++
Build/source/libs/icu/icu-xetex/common/ucnvmbcs.h | 490 ++
Build/source/libs/icu/icu-xetex/common/ucnvscsu.c | 2015 ++++++++
Build/source/libs/icu/icu-xetex/common/ucol_swp.c | 402 ++
Build/source/libs/icu/icu-xetex/common/ucol_swp.h | 58 +
Build/source/libs/icu/icu-xetex/common/udata.c | 1474 ++++++
Build/source/libs/icu/icu-xetex/common/udatamem.c | 160 +
Build/source/libs/icu/icu-xetex/common/udatamem.h | 61 +
Build/source/libs/icu/icu-xetex/common/udataswp.c | 415 ++
Build/source/libs/icu/icu-xetex/common/udataswp.h | 349 ++
Build/source/libs/icu/icu-xetex/common/uenum.c | 181 +
Build/source/libs/icu/icu-xetex/common/uenumimp.h | 153 +
Build/source/libs/icu/icu-xetex/common/uhash.c | 1001 ++++
Build/source/libs/icu/icu-xetex/common/uhash.h | 728 +++
.../source/libs/icu/icu-xetex/common/uhash_us.cpp | 68 +
Build/source/libs/icu/icu-xetex/common/uidna.cpp | 923 ++++
Build/source/libs/icu/icu-xetex/common/uinit.c | 113 +
Build/source/libs/icu/icu-xetex/common/uinvchar.c | 515 ++
Build/source/libs/icu/icu-xetex/common/uinvchar.h | 66 +
Build/source/libs/icu/icu-xetex/common/uiter.cpp | 1121 +++++
Build/source/libs/icu/icu-xetex/common/uloc.c | 3046 ++++++++++++
Build/source/libs/icu/icu-xetex/common/ulocimp.h | 24 +
Build/source/libs/icu/icu-xetex/common/umapfile.c | 494 ++
Build/source/libs/icu/icu-xetex/common/umapfile.h | 32 +
Build/source/libs/icu/icu-xetex/common/umath.c | 24 +
Build/source/libs/icu/icu-xetex/common/umutex.c | 636 +++
Build/source/libs/icu/icu-xetex/common/umutex.h | 143 +
Build/source/libs/icu/icu-xetex/common/unames.c | 2083 +++++++++
.../libs/icu/icu-xetex/common/unicode/brkiter.h | 557 +++
.../libs/icu/icu-xetex/common/unicode/caniter.h | 201 +
.../libs/icu/icu-xetex/common/unicode/chariter.h | 716 +++
.../libs/icu/icu-xetex/common/unicode/dbbi.h | 41 +
.../libs/icu/icu-xetex/common/unicode/docmain.h | 202 +
.../libs/icu/icu-xetex/common/unicode/locid.h | 765 +++
.../libs/icu/icu-xetex/common/unicode/normlzr.h | 823 ++++
.../libs/icu/icu-xetex/common/unicode/parseerr.h | 92 +
.../libs/icu/icu-xetex/common/unicode/parsepos.h | 230 +
.../icu/icu-xetex/common/unicode/platform.h.in | 313 ++
.../libs/icu/icu-xetex/common/unicode/ppalmos.h | 273 ++
.../libs/icu/icu-xetex/common/unicode/putil.h | 184 +
.../libs/icu/icu-xetex/common/unicode/pwin32.h | 311 ++
.../libs/icu/icu-xetex/common/unicode/rbbi.h | 700 +++
.../source/libs/icu/icu-xetex/common/unicode/rep.h | 259 +
.../libs/icu/icu-xetex/common/unicode/resbund.h | 485 ++
.../libs/icu/icu-xetex/common/unicode/schriter.h | 187 +
.../libs/icu/icu-xetex/common/unicode/strenum.h | 271 ++
.../libs/icu/icu-xetex/common/unicode/symtable.h | 112 +
.../libs/icu/icu-xetex/common/unicode/ubidi.h | 1999 ++++++++
.../libs/icu/icu-xetex/common/unicode/ubrk.h | 482 ++
.../libs/icu/icu-xetex/common/unicode/ucasemap.h | 395 ++
.../libs/icu/icu-xetex/common/unicode/ucat.h | 158 +
.../libs/icu/icu-xetex/common/unicode/uchar.h | 3013 ++++++++++++
.../libs/icu/icu-xetex/common/unicode/uchriter.h | 381 ++
.../libs/icu/icu-xetex/common/unicode/uclean.h | 267 ++
.../libs/icu/icu-xetex/common/unicode/ucnv.h | 1954 ++++++++
.../libs/icu/icu-xetex/common/unicode/ucnv_cb.h | 162 +
.../libs/icu/icu-xetex/common/unicode/ucnv_err.h | 456 ++
.../libs/icu/icu-xetex/common/unicode/uconfig.h | 215 +
.../libs/icu/icu-xetex/common/unicode/udata.h | 389 ++
.../libs/icu/icu-xetex/common/unicode/udeprctd.h | 50 +
.../libs/icu/icu-xetex/common/unicode/udraft.h | 186 +
.../libs/icu/icu-xetex/common/unicode/uenum.h | 134 +
.../libs/icu/icu-xetex/common/unicode/uidna.h | 312 ++
.../libs/icu/icu-xetex/common/unicode/uintrnal.h | 180 +
.../libs/icu/icu-xetex/common/unicode/uiter.h | 707 +++
.../libs/icu/icu-xetex/common/unicode/uloc.h | 931 ++++
.../libs/icu/icu-xetex/common/unicode/umachine.h | 338 ++
.../libs/icu/icu-xetex/common/unicode/umisc.h | 60 +
.../libs/icu/icu-xetex/common/unicode/unifilt.h | 127 +
.../libs/icu/icu-xetex/common/unicode/unifunct.h | 125 +
.../libs/icu/icu-xetex/common/unicode/unimatch.h | 163 +
.../libs/icu/icu-xetex/common/unicode/uniset.h | 1508 ++++++
.../libs/icu/icu-xetex/common/unicode/unistr.h | 4149 ++++++++++++++++
.../libs/icu/icu-xetex/common/unicode/unorm.h | 576 +++
.../libs/icu/icu-xetex/common/unicode/uobject.h | 308 ++
.../libs/icu/icu-xetex/common/unicode/uobslete.h | 32 +
.../libs/icu/icu-xetex/common/unicode/urename.h | 1730 +++++++
.../libs/icu/icu-xetex/common/unicode/urep.h | 155 +
.../libs/icu/icu-xetex/common/unicode/ures.h | 871 ++++
.../libs/icu/icu-xetex/common/unicode/uscript.h | 238 +
.../libs/icu/icu-xetex/common/unicode/uset.h | 1055 +++++
.../libs/icu/icu-xetex/common/unicode/usetiter.h | 318 ++
.../libs/icu/icu-xetex/common/unicode/ushape.h | 263 ++
.../libs/icu/icu-xetex/common/unicode/usprep.h | 156 +
.../libs/icu/icu-xetex/common/unicode/ustring.h | 1478 ++++++
.../libs/icu/icu-xetex/common/unicode/usystem.h | 46 +
.../libs/icu/icu-xetex/common/unicode/utext.h | 1558 ++++++
.../source/libs/icu/icu-xetex/common/unicode/utf.h | 227 +
.../libs/icu/icu-xetex/common/unicode/utf16.h | 605 +++
.../libs/icu/icu-xetex/common/unicode/utf32.h | 23 +
.../libs/icu/icu-xetex/common/unicode/utf8.h | 652 +++
.../libs/icu/icu-xetex/common/unicode/utf_old.h | 1171 +++++
.../libs/icu/icu-xetex/common/unicode/utrace.h | 358 ++
.../libs/icu/icu-xetex/common/unicode/utypes.h | 787 ++++
.../libs/icu/icu-xetex/common/unicode/uversion.h | 266 ++
Build/source/libs/icu/icu-xetex/common/unifilt.cpp | 68 +
.../source/libs/icu/icu-xetex/common/unifunct.cpp | 26 +
Build/source/libs/icu/icu-xetex/common/uniset.cpp | 2145 +++++++++
.../libs/icu/icu-xetex/common/uniset_props.cpp | 1394 ++++++
.../libs/icu/icu-xetex/common/unisetspan.cpp | 1508 ++++++
.../source/libs/icu/icu-xetex/common/unisetspan.h | 155 +
Build/source/libs/icu/icu-xetex/common/unistr.cpp | 1385 ++++++
.../libs/icu/icu-xetex/common/unistr_case.cpp | 246 +
.../libs/icu/icu-xetex/common/unistr_cnv.cpp | 372 ++
.../libs/icu/icu-xetex/common/unistr_props.cpp | 72 +
Build/source/libs/icu/icu-xetex/common/unorm.cpp | 4099 ++++++++++++++++
Build/source/libs/icu/icu-xetex/common/unorm_it.c | 643 +++
Build/source/libs/icu/icu-xetex/common/unorm_it.h | 148 +
.../libs/icu/icu-xetex/common/unorm_props_data.c | 3092 ++++++++++++
.../source/libs/icu/icu-xetex/common/unormcmp.cpp | 690 +++
Build/source/libs/icu/icu-xetex/common/unormimp.h | 792 ++++
Build/source/libs/icu/icu-xetex/common/uobject.cpp | 114 +
Build/source/libs/icu/icu-xetex/common/uprops.c | 545 +++
Build/source/libs/icu/icu-xetex/common/uprops.h | 426 ++
Build/source/libs/icu/icu-xetex/common/ures_cnv.c | 76 +
Build/source/libs/icu/icu-xetex/common/uresbund.c | 2629 +++++++++++
Build/source/libs/icu/icu-xetex/common/uresdata.c | 1095 +++++
Build/source/libs/icu/icu-xetex/common/uresdata.h | 233 +
Build/source/libs/icu/icu-xetex/common/uresimp.h | 243 +
Build/source/libs/icu/icu-xetex/common/usc_impl.c | 361 ++
Build/source/libs/icu/icu-xetex/common/usc_impl.h | 149 +
Build/source/libs/icu/icu-xetex/common/uscript.c | 112 +
Build/source/libs/icu/icu-xetex/common/uset.cpp | 634 +++
Build/source/libs/icu/icu-xetex/common/uset_imp.h | 56 +
.../libs/icu/icu-xetex/common/uset_props.cpp | 136 +
.../source/libs/icu/icu-xetex/common/usetiter.cpp | 150 +
Build/source/libs/icu/icu-xetex/common/ushape.c | 1198 +++++
Build/source/libs/icu/icu-xetex/common/usprep.cpp | 926 ++++
Build/source/libs/icu/icu-xetex/common/ustack.cpp | 61 +
Build/source/libs/icu/icu-xetex/common/ustr_cnv.c | 230 +
Build/source/libs/icu/icu-xetex/common/ustr_cnv.h | 42 +
Build/source/libs/icu/icu-xetex/common/ustr_imp.h | 211 +
Build/source/libs/icu/icu-xetex/common/ustr_wcs.c | 522 +++
Build/source/libs/icu/icu-xetex/common/ustrcase.c | 981 ++++
.../source/libs/icu/icu-xetex/common/ustrenum.cpp | 323 ++
Build/source/libs/icu/icu-xetex/common/ustrenum.h | 98 +
Build/source/libs/icu/icu-xetex/common/ustrfmt.c | 57 +
Build/source/libs/icu/icu-xetex/common/ustrfmt.h | 17 +
Build/source/libs/icu/icu-xetex/common/ustring.c | 1490 ++++++
Build/source/libs/icu/icu-xetex/common/ustrtrns.c | 1181 +++++
Build/source/libs/icu/icu-xetex/common/utext.cpp | 2822 +++++++++++
Build/source/libs/icu/icu-xetex/common/utf_impl.c | 364 ++
Build/source/libs/icu/icu-xetex/common/util.cpp | 443 ++
Build/source/libs/icu/icu-xetex/common/util.h | 261 ++
.../libs/icu/icu-xetex/common/util_props.cpp | 214 +
Build/source/libs/icu/icu-xetex/common/utrace.c | 486 ++
Build/source/libs/icu/icu-xetex/common/utracimp.h | 384 ++
Build/source/libs/icu/icu-xetex/common/utrie.c | 1210 +++++
Build/source/libs/icu/icu-xetex/common/utrie.h | 792 ++++
Build/source/libs/icu/icu-xetex/common/utypes.c | 199 +
Build/source/libs/icu/icu-xetex/common/uvector.cpp | 472 ++
Build/source/libs/icu/icu-xetex/common/uvector.h | 408 ++
.../source/libs/icu/icu-xetex/common/uvectr32.cpp | 273 ++
Build/source/libs/icu/icu-xetex/common/uvectr32.h | 292 ++
Build/source/libs/icu/icu-xetex/common/wintz.c | 688 +++
Build/source/libs/icu/icu-xetex/common/wintz.h | 37 +
280 files changed, 167181 insertions(+)
create mode 100644 Build/source/libs/icu/icu-xetex/common/Makefile.in
create mode 100644 Build/source/libs/icu/icu-xetex/common/bmpset.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/bmpset.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/brkeng.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/brkeng.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/brkiter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/caniter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/chariter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/charstr.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/cmemory.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/cmemory.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/common.rc
create mode 100644 Build/source/libs/icu/icu-xetex/common/common.vcproj
create mode 100644 Build/source/libs/icu/icu-xetex/common/cpputils.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/cstring.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/cstring.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/cwchar.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/cwchar.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/dictbe.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/dictbe.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/hash.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/icucfg.h.in
create mode 100644 Build/source/libs/icu/icu-xetex/common/localsvc.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/locbased.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/locbased.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/locid.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/locmap.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/locmap.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/locutil.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/locutil.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/msvcres.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/mutex.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/normlzr.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/parsepos.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/propname.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/propname.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/punycode.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/punycode.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/putil.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/putilimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbi.cpp
create mode 100755 Build/source/libs/icu/icu-xetex/common/rbbicst.pl
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbidata.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbidata.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbinode.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbinode.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbirb.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbirb.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbirpt.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbirpt.txt
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbiscan.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbiscan.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbisetb.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbisetb.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbistbl.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbitblb.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/rbbitblb.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/resbund.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/resbund_cnv.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ruleiter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ruleiter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/schriter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/serv.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/serv.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/servlk.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/servlkf.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/servloc.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/servls.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/servnotf.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/servnotf.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/servrbf.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/servslkf.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/sprpimpl.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/triedict.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/triedict.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uarrsort.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uarrsort.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uassert.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidi.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidi_props.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidi_props.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidi_props_data.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidiimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidiln.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubidiwrt.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubrk.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ubrkimpl.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucase.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucase.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucase_props_data.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucasemap.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucat.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uchar.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uchar_props_data.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uchriter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucln.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucln_cmn.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucln_cmn.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucmndata.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucmndata.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv2022.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_bld.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_bld.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_cb.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_cnv.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_cnv.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_err.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_ext.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_ext.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_imp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_io.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_io.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_lmb.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_set.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_u16.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_u32.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_u7.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnv_u8.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvbocu.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvdisp.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvhz.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvisci.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvlat1.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvmbcs.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvmbcs.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucnvscsu.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucol_swp.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ucol_swp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/udata.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/udatamem.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/udatamem.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/udataswp.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/udataswp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uenum.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uenumimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uhash.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uhash.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uhash_us.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uidna.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uinit.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uinvchar.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uinvchar.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uiter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uloc.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ulocimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/umapfile.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/umapfile.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/umath.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/umutex.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/umutex.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unames.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/brkiter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/caniter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/chariter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/dbbi.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/docmain.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/locid.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/normlzr.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/parseerr.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/parsepos.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/platform.h.in
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ppalmos.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/putil.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/pwin32.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/rbbi.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/rep.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/resbund.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/schriter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/strenum.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/symtable.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ubidi.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ubrk.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ucasemap.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ucat.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uchar.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uchriter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uclean.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ucnv.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ucnv_cb.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ucnv_err.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uconfig.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/udata.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/udeprctd.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/udraft.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uenum.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uidna.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uintrnal.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uiter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uloc.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/umachine.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/umisc.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/unifilt.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/unifunct.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/unimatch.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uniset.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/unistr.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/unorm.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uobject.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uobslete.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/urename.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/urep.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ures.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uscript.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uset.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/usetiter.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ushape.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/usprep.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/ustring.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/usystem.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utext.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utf.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utf16.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utf32.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utf8.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utf_old.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utrace.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/utypes.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unicode/uversion.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unifilt.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unifunct.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uniset.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uniset_props.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unisetspan.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unisetspan.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unistr.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unistr_case.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unistr_cnv.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unistr_props.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unorm.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unorm_it.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/unorm_it.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/unorm_props_data.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/unormcmp.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/unormimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uobject.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uprops.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uprops.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ures_cnv.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uresbund.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uresdata.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uresdata.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uresimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/usc_impl.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/usc_impl.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uscript.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uset.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uset_imp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uset_props.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/usetiter.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ushape.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/usprep.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustack.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustr_cnv.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustr_cnv.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustr_imp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustr_wcs.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrcase.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrenum.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrenum.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrfmt.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrfmt.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustring.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/ustrtrns.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/utext.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/utf_impl.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/util.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/util.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/util_props.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/utrace.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/utracimp.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/utrie.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/utrie.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/utypes.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/uvector.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uvector.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/uvectr32.cpp
create mode 100644 Build/source/libs/icu/icu-xetex/common/uvectr32.h
create mode 100644 Build/source/libs/icu/icu-xetex/common/wintz.c
create mode 100644 Build/source/libs/icu/icu-xetex/common/wintz.h
(limited to 'Build/source/libs/icu/icu-xetex/common')
diff --git a/Build/source/libs/icu/icu-xetex/common/Makefile.in b/Build/source/libs/icu/icu-xetex/common/Makefile.in
new file mode 100644
index 00000000000..6efb25907d9
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/Makefile.in
@@ -0,0 +1,203 @@
+#******************************************************************************
+#
+# Copyright (C) 1999-2007, International Business Machines
+# Corporation and others. All Rights Reserved.
+#
+#******************************************************************************
+## Makefile.in for ICU - icuuc.so
+## Stephen F. Booth
+
+## Source directory information
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+
+top_builddir = ..
+
+## All the flags and other definitions are included here.
+include $(top_builddir)/icudefs.mk
+
+## Build directory information
+subdir = common
+
+# for service hook
+LOCALSVC_CPP=localsvc.cpp
+SVC_HOOK_INC=$(top_builddir)/common/svchook.mk
+
+## Extra files to remove for 'make clean'
+CLEANFILES = *~ $(DEPS) $(IMPORT_LIB) $(MIDDLE_IMPORT_LIB) $(FINAL_IMPORT_LIB) $(SVC_HOOK_INC)
+
+## Target information
+
+TARGET_STUBNAME=$(COMMON_STUBNAME)
+
+ifneq ($(ENABLE_STATIC),)
+TARGET = $(LIBDIR)/$(LIBSICU)$(TARGET_STUBNAME)$(ICULIBSUFFIX).$(A)
+endif
+
+ifneq ($(ENABLE_SHARED),)
+SO_TARGET = $(LIBDIR)/$(LIBICU)$(TARGET_STUBNAME)$(ICULIBSUFFIX).$(SO)
+ALL_SO_TARGETS = $(SO_TARGET) $(MIDDLE_SO_TARGET) $(FINAL_SO_TARGET) $(SHARED_OBJECT)
+
+ifeq ($(ENABLE_SO_VERSION_DATA),1)
+SO_VERSION_DATA = common.res
+endif
+
+ifeq ($(OS390BATCH),1)
+BATCH_TARGET = $(BATCH_COMMON_TARGET)
+BATCH_LIBS = $(BATCH_LIBICUDT) -lm
+endif # OS390BATCH
+
+endif # ENABLE_SHARED
+
+ALL_TARGETS = $(TARGET) $(ALL_SO_TARGETS) $(BATCH_TARGET)
+
+DYNAMICCPPFLAGS = $(SHAREDLIBCPPFLAGS)
+DYNAMICCFLAGS = $(SHAREDLIBCFLAGS)
+DYNAMICCXXFLAGS = $(SHAREDLIBCXXFLAGS)
+CFLAGS += $(LIBCFLAGS)
+CXXFLAGS += $(LIBCXXFLAGS)
+
+ifneq ($(top_builddir),$(top_srcdir))
+CPPFLAGS += -I$(top_builddir)/common
+endif
+CPPFLAGS += -I$(srcdir) -I$(top_srcdir)/i18n $(LIBCPPFLAGS)
+DEFS += -DU_COMMON_IMPLEMENTATION
+LDFLAGS += $(LDFLAGSICUUC)
+
+# $(LIBICUDT) is either stub data or the real DLL common data.
+LIBS = $(LIBICUDT) $(DEFAULT_LIBS)
+
+OBJECTS = putil.o umath.o utypes.o uinvchar.o umutex.o ucln_cmn.o uinit.o uobject.o cmemory.o \
+udata.o ucmndata.o udatamem.o umapfile.o udataswp.o ucol_swp.o utrace.o \
+uhash.o uhash_us.o uenum.o ustrenum.o uvector.o ustack.o uvectr32.o \
+ucnv.o ucnv_bld.o ucnv_cnv.o ucnv_io.o ucnv_cb.o ucnv_err.o ucnvlat1.o \
+ucnv_u7.o ucnv_u8.o ucnv_u16.o ucnv_u32.o ucnvscsu.o ucnvbocu.o \
+ucnv_ext.o ucnvmbcs.o ucnv2022.o ucnvhz.o ucnv_lmb.o ucnvisci.o ucnvdisp.o ucnv_set.o \
+uresbund.o ures_cnv.o uresdata.o resbund.o resbund_cnv.o \
+ucat.o locmap.o uloc.o locid.o locutil.o \
+ustr_cnv.o unistr_cnv.o unistr.o unistr_case.o unistr_props.o \
+utf_impl.o ustring.o ustrcase.o ucasemap.o cstring.o ustrfmt.o ustrtrns.o ustr_wcs.o utext.o \
+normlzr.o unorm.o unormcmp.o unorm_it.o chariter.o schriter.o uchriter.o uiter.o \
+uchar.o uprops.o ucase.o propname.o ubidi_props.o ubidi.o ubidiwrt.o ubidiln.o ushape.o \
+uscript.o usc_impl.o unames.o \
+utrie.o bmpset.o unisetspan.o uset_props.o uniset_props.o uset.o uniset.o usetiter.o ruleiter.o caniter.o unifilt.o unifunct.o \
+uarrsort.o brkiter.o ubrk.o brkeng.o dictbe.o triedict.o \
+rbbi.o rbbidata.o rbbinode.o rbbirb.o rbbiscan.o rbbisetb.o rbbistbl.o rbbitblb.o \
+serv.o servnotf.o servls.o servlk.o servlkf.o servrbf.o servslkf.o \
+uidna.o usprep.o punycode.o \
+util.o util_props.o parsepos.o locbased.o cwchar.o wintz.o
+
+## Header files to install
+HEADERS = $(srcdir)/unicode/*.h unicode/*.h
+
+STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O))
+
+DEPS = $(OBJECTS:.o=.d)
+
+-include Makefile.local
+
+-include $(SVC_HOOK_INC)
+
+
+## List of phony targets
+.PHONY : all all-local install install-local clean clean-local \
+distclean distclean-local install-library install-headers dist \
+dist-local check check-local
+
+## Clear suffix list
+.SUFFIXES :
+
+## List of standard targets
+all: all-local
+install: install-local
+clean: clean-local
+distclean : distclean-local
+dist: dist-local
+check: all check-local
+
+all-local: $(ALL_TARGETS) unicode/platform.h
+
+install-local: install-headers install-library
+
+install-library: all-local
+ $(MKINSTALLDIRS) $(DESTDIR)$(libdir)
+ifneq ($(ENABLE_STATIC),)
+ $(INSTALL-L) $(TARGET) $(DESTDIR)$(libdir)
+endif
+ifneq ($(ENABLE_SHARED),)
+ $(INSTALL-L) $(FINAL_SO_TARGET) $(DESTDIR)$(libdir)
+ifneq ($(FINAL_SO_TARGET),$(SO_TARGET))
+ cd $(DESTDIR)$(libdir) && $(RM) $(notdir $(SO_TARGET)) && ln -s $(notdir $(FINAL_SO_TARGET)) $(notdir $(SO_TARGET))
+ifneq ($(FINAL_SO_TARGET),$(MIDDLE_SO_TARGET))
+ cd $(DESTDIR)$(libdir) && $(RM) $(notdir $(MIDDLE_SO_TARGET)) && ln -s $(notdir $(FINAL_SO_TARGET)) $(notdir $(MIDDLE_SO_TARGET))
+endif
+endif
+ifneq ($(IMPORT_LIB_EXT),)
+ $(INSTALL-L) $(FINAL_IMPORT_LIB) $(DESTDIR)$(libdir)
+ifneq ($(IMPORT_LIB),$(FINAL_IMPORT_LIB))
+ cd $(DESTDIR)$(libdir) && $(RM) $(notdir $(IMPORT_LIB)) && ln -s $(notdir $(FINAL_IMPORT_LIB)) $(notdir $(IMPORT_LIB))
+endif
+ifneq ($(MIDDLE_IMPORT_LIB),$(FINAL_IMPORT_LIB))
+ cd $(DESTDIR)$(libdir) && $(RM) $(notdir $(MIDDLE_IMPORT_LIB)) && ln -s $(notdir $(FINAL_IMPORT_LIB)) $(notdir $(MIDDLE_IMPORT_LIB))
+endif
+endif
+endif
+
+$(SVC_HOOK_INC):
+ @echo generating $@
+ @-test -f $(top_srcdir)/common/$(LOCALSVC_CPP) && ( echo "have $(LOCALSVC_CPP) - U_LOCAL_SERVICE_HOOK=1" ; \
+ echo 'CPPFLAGS +=-DU_LOCAL_SERVICE_HOOK=1' > $@ ; \
+ echo 'OBJECTS += $(LOCALSVC_CPP:%.cpp=%.o)' >> $@ \
+ ) ; true
+ @echo "# Autogenerated by Makefile" >> $@
+
+install-headers:
+ $(MKINSTALLDIRS) $(DESTDIR)$(includedir)/unicode
+ @for file in $(HEADERS); do \
+ echo "$(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/unicode"; \
+ $(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/unicode || exit; \
+ done
+
+dist-local:
+
+clean-local:
+ test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
+ $(RMV) $(OBJECTS) $(STATIC_OBJECTS) $(ALL_TARGETS) $(SO_VERSION_DATA)
+
+distclean-local: clean-local
+ $(RMV) Makefile icucfg.h unicode/platform.h $(SVC_HOOK_INC)
+
+check-local:
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(SVC_HOOK_INC)
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+unicode/platform.h: $(srcdir)/unicode/platform.h.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+ifneq ($(ENABLE_STATIC),)
+$(TARGET): $(STATIC_OBJECTS)
+ $(AR) $(ARFLAGS) $(AR_OUTOPT)$@ $^
+ $(RANLIB) $@
+endif
+
+ifneq ($(ENABLE_SHARED),)
+$(SHARED_OBJECT): $(OBJECTS) $(SO_VERSION_DATA)
+ $(SHLIB.cc) $(LD_SONAME) $(OUTOPT)$@ $^ $(LIBS)
+
+ifeq ($(OS390BATCH),1)
+$(BATCH_TARGET):$(OBJECTS)
+ $(SHLIB.cc) $(LD_SONAME) $(OUTOPT)$@ $^ $(BATCH_LIBS)
+endif # OS390BATCH
+endif # ENABLE_SHARED
+
+ifeq (,$(MAKECMDGOALS))
+-include $(DEPS)
+else
+ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
+-include $(DEPS)
+endif
+endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/bmpset.cpp b/Build/source/libs/icu/icu-xetex/common/bmpset.cpp
new file mode 100644
index 00000000000..24b3545f2dd
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/bmpset.cpp
@@ -0,0 +1,723 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: bmpset.cpp
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2007jan29
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uniset.h"
+#include "cmemory.h"
+#include "bmpset.h"
+
+U_NAMESPACE_BEGIN
+
+BMPSet::BMPSet(const int32_t *parentList, int32_t parentListLength) :
+ list(parentList), listLength(parentListLength) {
+ uprv_memset(asciiBytes, 0, sizeof(asciiBytes));
+ uprv_memset(table7FF, 0, sizeof(table7FF));
+ uprv_memset(bmpBlockBits, 0, sizeof(bmpBlockBits));
+
+ /*
+ * Set the list indexes for binary searches for
+ * U+0800, U+1000, U+2000, .., U+F000, U+10000.
+ * U+0800 is the first 3-byte-UTF-8 code point. Lower code points are
+ * looked up in the bit tables.
+ * The last pair of indexes is for finding supplementary code points.
+ */
+ list4kStarts[0]=findCodePoint(0x800, 0, listLength-1);
+ int32_t i;
+ for(i=1; i<=0x10; ++i) {
+ list4kStarts[i]=findCodePoint(i<<12, list4kStarts[i-1], listLength-1);
+ }
+ list4kStarts[0x11]=listLength-1;
+
+ initBits();
+ overrideIllegal();
+}
+
+BMPSet::BMPSet(const BMPSet &otherBMPSet, const int32_t *newParentList, int32_t newParentListLength) :
+ list(newParentList), listLength(newParentListLength) {
+ uprv_memcpy(asciiBytes, otherBMPSet.asciiBytes, sizeof(asciiBytes));
+ uprv_memcpy(table7FF, otherBMPSet.table7FF, sizeof(table7FF));
+ uprv_memcpy(bmpBlockBits, otherBMPSet.bmpBlockBits, sizeof(bmpBlockBits));
+ uprv_memcpy(list4kStarts, otherBMPSet.list4kStarts, sizeof(list4kStarts));
+}
+
+BMPSet::~BMPSet() {
+}
+
+/*
+ * Set bits in a bit rectangle in "vertical" bit organization.
+ * start>6;
+ int32_t trail=start&0x3f;
+
+ // Set one bit indicating an all-one block.
+ uint32_t bits=(uint32_t)1<>6;
+ int32_t limitTrail=limit&0x3f;
+
+ if(lead==limitLead) {
+ // Partial vertical bit column.
+ while(trail0) {
+ do {
+ table[trail++]|=bits;
+ } while(trail<64);
+ ++lead;
+ }
+ if(lead=0x80) {
+ break;
+ }
+ do {
+ asciiBytes[start++]=1;
+ } while(start0x800) {
+ start=0x800;
+ break;
+ }
+
+ start=list[listIndex++];
+ if(listIndex0x10000) {
+ limit=0x10000;
+ }
+
+ if(start>=6;
+ bmpBlockBits[start&0x3f]|=0x10001<<(start>>6);
+ start=(start+1)<<6; // Round up to the next block boundary.
+ minStart=start; // Ignore further ranges in this block.
+ }
+ if(start>6, limit>>6);
+ }
+
+ if(limit&0x3f) {
+ // Mixed-value block of 64 code points.
+ limit>>=6;
+ bmpBlockBits[limit&0x3f]|=0x10001<<(limit>>6);
+ limit=(limit+1)<<6; // Round up to the next block boundary.
+ minStart=limit; // Ignore further ranges in this block.
+ }
+ }
+ }
+
+ if(limit==0x10000) {
+ break;
+ }
+
+ start=list[listIndex++];
+ if(listIndex= hi || c >= list[hi-1])
+ return hi;
+ // invariant: c >= list[lo]
+ // invariant: c < list[hi]
+ for (;;) {
+ int32_t i = (lo + hi) >> 1;
+ if (i == lo) {
+ break; // Found!
+ } else if (c < list[i]) {
+ hi = i;
+ } else {
+ lo = i;
+ }
+ }
+ return hi;
+}
+
+UBool
+BMPSet::contains(UChar32 c) const {
+ if((uint32_t)c<=0x7f) {
+ return (UBool)asciiBytes[c];
+ } else if((uint32_t)c<=0x7ff) {
+ return (UBool)((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0);
+ } else if((uint32_t)c<0xd800 || (c>=0xe000 && c<=0xffff)) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ return (UBool)twoBits;
+ } else {
+ // Look up the code point in its 4k block of code points.
+ return containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]);
+ }
+ } else if((uint32_t)c<=0x10ffff) {
+ // surrogate or supplementary code point
+ return containsSlow(c, list4kStarts[0xd], list4kStarts[0x11]);
+ } else {
+ // Out-of-range code points get FALSE, consistent with long-standing
+ // behavior of UnicodeSet::contains(c).
+ return FALSE;
+ }
+}
+
+/*
+ * Check for sufficient length for trail unit for each surrogate pair.
+ * Handle single surrogates as surrogate code points as usual in ICU.
+ */
+const UChar *
+BMPSet::span(const UChar *s, const UChar *limit, USetSpanCondition spanCondition) const {
+ UChar c, c2;
+
+ if(spanCondition) {
+ // span
+ do {
+ c=*s;
+ if(c<=0x7f) {
+ if(!asciiBytes[c]) {
+ break;
+ }
+ } else if(c<=0x7ff) {
+ if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))==0) {
+ break;
+ }
+ } else if(c<0xd800 || c>=0xe000) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ if(twoBits==0) {
+ break;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ if(!containsSlow(c, list4kStarts[lead], list4kStarts[lead+1])) {
+ break;
+ }
+ }
+ } else if(c>=0xdc00 || (s+1)==limit || (c2=s[1])<0xdc00 || c2>=0xe000) {
+ // surrogate code point
+ if(!containsSlow(c, list4kStarts[0xd], list4kStarts[0xe])) {
+ break;
+ }
+ } else {
+ // surrogate pair
+ if(!containsSlow(U16_GET_SUPPLEMENTARY(c, c2), list4kStarts[0x10], list4kStarts[0x11])) {
+ break;
+ }
+ ++s;
+ }
+ } while(++s>6)))!=0) {
+ break;
+ }
+ } else if(c<0xd800 || c>=0xe000) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ if(twoBits!=0) {
+ break;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ if(containsSlow(c, list4kStarts[lead], list4kStarts[lead+1])) {
+ break;
+ }
+ }
+ } else if(c>=0xdc00 || (s+1)==limit || (c2=s[1])<0xdc00 || c2>=0xe000) {
+ // surrogate code point
+ if(containsSlow(c, list4kStarts[0xd], list4kStarts[0xe])) {
+ break;
+ }
+ } else {
+ // surrogate pair
+ if(containsSlow(U16_GET_SUPPLEMENTARY(c, c2), list4kStarts[0x10], list4kStarts[0x11])) {
+ break;
+ }
+ ++s;
+ }
+ } while(++s>6)))==0) {
+ break;
+ }
+ } else if(c<0xd800 || c>=0xe000) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ if(twoBits==0) {
+ break;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ if(!containsSlow(c, list4kStarts[lead], list4kStarts[lead+1])) {
+ break;
+ }
+ }
+ } else if(c<0xdc00 || s==limit || (c2=*(limit-1))<0xd800 || c2>=0xdc00) {
+ // surrogate code point
+ if(!containsSlow(c, list4kStarts[0xd], list4kStarts[0xe])) {
+ break;
+ }
+ } else {
+ // surrogate pair
+ if(!containsSlow(U16_GET_SUPPLEMENTARY(c2, c), list4kStarts[0x10], list4kStarts[0x11])) {
+ break;
+ }
+ --limit;
+ }
+ if(s==limit) {
+ return s;
+ }
+ }
+ } else {
+ // span not
+ for(;;) {
+ c=*(--limit);
+ if(c<=0x7f) {
+ if(asciiBytes[c]) {
+ break;
+ }
+ } else if(c<=0x7ff) {
+ if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) {
+ break;
+ }
+ } else if(c<0xd800 || c>=0xe000) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ if(twoBits!=0) {
+ break;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ if(containsSlow(c, list4kStarts[lead], list4kStarts[lead+1])) {
+ break;
+ }
+ }
+ } else if(c<0xdc00 || s==limit || (c2=*(limit-1))<0xd800 || c2>=0xdc00) {
+ // surrogate code point
+ if(containsSlow(c, list4kStarts[0xd], list4kStarts[0xe])) {
+ break;
+ }
+ } else {
+ // surrogate pair
+ if(containsSlow(U16_GET_SUPPLEMENTARY(c2, c), list4kStarts[0x10], list4kStarts[0x11])) {
+ break;
+ }
+ --limit;
+ }
+ if(s==limit) {
+ return s;
+ }
+ }
+ }
+ return limit+1;
+}
+
+/*
+ * Precheck for sufficient trail bytes at end of string only once per span.
+ * Check validity.
+ */
+const uint8_t *
+BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const {
+ const uint8_t *limit=s+length;
+ uint8_t b=*s;
+ if((int8_t)b>=0) {
+ // Initial all-ASCII span.
+ if(spanCondition) {
+ do {
+ if(!asciiBytes[b] || ++s==limit) {
+ return s;
+ }
+ b=*s;
+ } while((int8_t)b>=0);
+ } else {
+ do {
+ if(asciiBytes[b] || ++s==limit) {
+ return s;
+ }
+ b=*s;
+ } while((int8_t)b>=0);
+ }
+ length=(int32_t)(limit-s);
+ }
+
+ if(spanCondition!=USET_SPAN_NOT_CONTAINED) {
+ spanCondition=USET_SPAN_CONTAINED; // Pin to 0/1 values.
+ }
+
+ const uint8_t *limit0=limit;
+
+ /*
+ * Make sure that the last 1/2/3/4-byte sequence before limit is complete
+ * or runs into a lead byte.
+ * In the span loop compare s with limit only once
+ * per multi-byte character.
+ *
+ * Give a trailing illegal sequence the same value as the result of contains(FFFD),
+ * including it if that is part of the span, otherwise set limit0 to before
+ * the truncated sequence.
+ */
+ b=*(limit-1);
+ if((int8_t)b<0) {
+ // b>=0x80: lead or trail byte
+ if(b<0xc0) {
+ // single trail byte, check for preceding 3- or 4-byte lead byte
+ if(length>=2 && (b=*(limit-2))>=0xe0) {
+ limit-=2;
+ if(asciiBytes[0x80]!=spanCondition) {
+ limit0=limit;
+ }
+ } else if(b<0xc0 && b>=0x80 && length>=3 && (b=*(limit-3))>=0xf0) {
+ // 4-byte lead byte with only two trail bytes
+ limit-=3;
+ if(asciiBytes[0x80]!=spanCondition) {
+ limit0=limit;
+ }
+ }
+ } else {
+ // lead byte with no trail bytes
+ --limit;
+ if(asciiBytes[0x80]!=spanCondition) {
+ limit0=limit;
+ }
+ }
+ }
+
+ uint8_t t1, t2, t3;
+
+ while(s=0xe0) {
+ if(b<0xf0) {
+ if( /* handle U+0000..U+FFFF inline */
+ (t1=(uint8_t)(s[0]-0x80)) <= 0x3f &&
+ (t2=(uint8_t)(s[1]-0x80)) <= 0x3f
+ ) {
+ b&=0xf;
+ uint32_t twoBits=(bmpBlockBits[t1]>>b)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with this lead byte and middle trail byte
+ // are either in the set or not.
+ if(twoBits!=(uint32_t)spanCondition) {
+ return s-1;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ UChar32 c=(b<<12)|(t1<<6)|t2;
+ if(containsSlow(c, list4kStarts[b], list4kStarts[b+1]) != spanCondition) {
+ return s-1;
+ }
+ }
+ s+=2;
+ continue;
+ }
+ } else if( /* handle U+10000..U+10FFFF inline */
+ (t1=(uint8_t)(s[0]-0x80)) <= 0x3f &&
+ (t2=(uint8_t)(s[1]-0x80)) <= 0x3f &&
+ (t3=(uint8_t)(s[2]-0x80)) <= 0x3f
+ ) {
+ // Give an illegal sequence the same value as the result of contains(FFFD).
+ UChar32 c=((UChar32)(b-0xf0)<<18)|((UChar32)t1<<12)|(t2<<6)|t3;
+ if( ( (0x10000<=c && c<=0x10ffff) ?
+ containsSlow(c, list4kStarts[0x10], list4kStarts[0x11]) :
+ asciiBytes[0x80]
+ ) != spanCondition
+ ) {
+ return s-1;
+ }
+ s+=3;
+ continue;
+ }
+ } else /* 0xc0<=b<0xe0 */ {
+ if( /* handle U+0000..U+07FF inline */
+ (t1=(uint8_t)(*s-0x80)) <= 0x3f
+ ) {
+ if(((table7FF[t1]&((uint32_t)1<<(b&0x1f)))!=0) != spanCondition) {
+ return s-1;
+ }
+ ++s;
+ continue;
+ }
+ }
+
+ // Give an illegal sequence the same value as the result of contains(FFFD).
+ // Handle each byte of an illegal sequence separately to simplify the code;
+ // no need to optimize error handling.
+ if(asciiBytes[0x80]!=spanCondition) {
+ return s-1;
+ }
+ }
+
+ return limit0;
+}
+
+/*
+ * While going backwards through UTF-8 optimize only for ASCII.
+ * Unlike UTF-16, UTF-8 is not forward-backward symmetrical, that is, it is not
+ * possible to tell from the last byte in a multi-byte sequence how many
+ * preceding bytes there should be. Therefore, going backwards through UTF-8
+ * is much harder than going forward.
+ */
+int32_t
+BMPSet::spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const {
+ if(spanCondition!=USET_SPAN_NOT_CONTAINED) {
+ spanCondition=USET_SPAN_CONTAINED; // Pin to 0/1 values.
+ }
+
+ uint8_t b;
+
+ do {
+ b=s[--length];
+ if((int8_t)b>=0) {
+ // ASCII sub-span
+ if(spanCondition) {
+ do {
+ if(!asciiBytes[b]) {
+ return length+1;
+ } else if(length==0) {
+ return 0;
+ }
+ b=s[--length];
+ } while((int8_t)b>=0);
+ } else {
+ do {
+ if(asciiBytes[b]) {
+ return length+1;
+ } else if(length==0) {
+ return 0;
+ }
+ b=s[--length];
+ } while((int8_t)b>=0);
+ }
+ }
+
+ int32_t prev=length;
+ UChar32 c;
+ if(b<0xc0) {
+ // trail byte: collect a multi-byte character
+ c=utf8_prevCharSafeBody(s, 0, &length, b, -1);
+ if(c<0) {
+ c=0xfffd;
+ }
+ } else {
+ // lead byte in last-trail position
+ c=0xfffd;
+ }
+ // c is a valid code point, not ASCII, not a surrogate
+ if(c<=0x7ff) {
+ if(((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) != spanCondition) {
+ return prev+1;
+ }
+ } else if(c<=0xffff) {
+ int lead=c>>12;
+ uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
+ if(twoBits<=1) {
+ // All 64 code points with the same bits 15..6
+ // are either in the set or not.
+ if(twoBits!=(uint32_t)spanCondition) {
+ return prev+1;
+ }
+ } else {
+ // Look up the code point in its 4k block of code points.
+ if(containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]) != spanCondition) {
+ return prev+1;
+ }
+ }
+ } else {
+ if(containsSlow(c, list4kStarts[0x10], list4kStarts[0x11]) != spanCondition) {
+ return prev+1;
+ }
+ }
+ } while(length>0);
+ return 0;
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/bmpset.h b/Build/source/libs/icu/icu-xetex/common/bmpset.h
new file mode 100644
index 00000000000..d9e08eaa66f
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/bmpset.h
@@ -0,0 +1,161 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: bmpset.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2007jan29
+* created by: Markus W. Scherer
+*/
+
+#ifndef __BMPSET_H__
+#define __BMPSET_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uniset.h"
+
+U_NAMESPACE_BEGIN
+
+/*
+ * Helper class for frozen UnicodeSets, implements contains() and span()
+ * optimized for BMP code points. Structured to be UTF-8-friendly.
+ *
+ * ASCII: Look up bytes.
+ * 2-byte characters: Bits organized vertically.
+ * 3-byte characters: Use zero/one/mixed data per 64-block in U+0000..U+FFFF,
+ * with mixed for illegal ranges.
+ * Supplementary characters: Call contains() on the parent set.
+ */
+class BMPSet : public UMemory {
+public:
+ BMPSet(const int32_t *parentList, int32_t parentListLength);
+ BMPSet(const BMPSet &otherBMPSet, const int32_t *newParentList, int32_t newParentListLength);
+ virtual ~BMPSet();
+
+ virtual UBool contains(UChar32 c) const;
+
+ /*
+ * Span the initial substring for which each character c has spanCondition==contains(c).
+ * It must be s0 and spanCondition==0 or 1.
+ * @return The string pointer which limits the span.
+ */
+ const uint8_t *spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const;
+
+ /*
+ * Span the trailing substring for which each character c has spanCondition==contains(c).
+ * It must be length>0 and spanCondition==0 or 1.
+ * @return The start of the span.
+ */
+ int32_t spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCondition) const;
+
+private:
+ void initBits();
+ void overrideIllegal();
+
+ /**
+ * Same as UnicodeSet::findCodePoint(UChar32 c) const except that the
+ * binary search is restricted for finding code points in a certain range.
+ *
+ * For restricting the search for finding in the range start..end,
+ * pass in
+ * lo=findCodePoint(start) and
+ * hi=findCodePoint(end)
+ * with 0<=lo<=hi= 0 && breakType < (int32_t)(sizeof(fHandled)/sizeof(fHandled[0]))
+ && fHandled[breakType] != 0 && fHandled[breakType]->contains(c));
+}
+
+int32_t
+UnhandledEngine::findBreaks( UText *text,
+ int32_t startPos,
+ int32_t endPos,
+ UBool reverse,
+ int32_t breakType,
+ UStack &/*foundBreaks*/ ) const {
+ if (breakType >= 0 && breakType < (int32_t)(sizeof(fHandled)/sizeof(fHandled[0]))) {
+ UChar32 c = utext_current32(text);
+ if (reverse) {
+ while((int32_t)utext_getNativeIndex(text) > startPos && fHandled[breakType]->contains(c)) {
+ c = utext_previous32(text);
+ }
+ }
+ else {
+ while((int32_t)utext_getNativeIndex(text) < endPos && fHandled[breakType]->contains(c)) {
+ utext_next32(text); // TODO: recast loop to work with post-increment operations.
+ c = utext_current32(text);
+ }
+ }
+ }
+ return 0;
+}
+
+void
+UnhandledEngine::handleCharacter(UChar32 c, int32_t breakType) {
+ if (breakType >= 0 && breakType < (int32_t)(sizeof(fHandled)/sizeof(fHandled[0]))) {
+ if (fHandled[breakType] == 0) {
+ fHandled[breakType] = new UnicodeSet();
+ if (fHandled[breakType] == 0) {
+ return;
+ }
+ }
+ if (!fHandled[breakType]->contains(c)) {
+ UErrorCode status = U_ZERO_ERROR;
+ // Apply the entire script of the character.
+ int32_t script = u_getIntPropertyValue(c, UCHAR_SCRIPT);
+ fHandled[breakType]->applyIntPropertyValue(UCHAR_SCRIPT, script, status);
+ }
+ }
+}
+
+/*
+ ******************************************************************
+ */
+
+ICULanguageBreakFactory::ICULanguageBreakFactory(UErrorCode &/*status*/) {
+ fEngines = 0;
+}
+
+ICULanguageBreakFactory::~ICULanguageBreakFactory() {
+ if (fEngines != 0) {
+ delete fEngines;
+ }
+}
+
+U_NAMESPACE_END
+U_CDECL_BEGIN
+static void U_CALLCONV _deleteEngine(void *obj) {
+ delete (const U_NAMESPACE_QUALIFIER LanguageBreakEngine *) obj;
+}
+U_CDECL_END
+U_NAMESPACE_BEGIN
+
+const LanguageBreakEngine *
+ICULanguageBreakFactory::getEngineFor(UChar32 c, int32_t breakType) {
+ UBool needsInit;
+ int32_t i;
+ const LanguageBreakEngine *lbe = NULL;
+ UErrorCode status = U_ZERO_ERROR;
+
+ // TODO: The global mutex should not be used.
+ // The global mutex should only be used for short periods.
+ // A ICULanguageBreakFactory specific mutex should be used.
+ umtx_lock(NULL);
+ needsInit = (UBool)(fEngines == NULL);
+ if (!needsInit) {
+ i = fEngines->size();
+ while (--i >= 0) {
+ lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i));
+ if (lbe != NULL && lbe->handles(c, breakType)) {
+ break;
+ }
+ lbe = NULL;
+ }
+ }
+ umtx_unlock(NULL);
+
+ if (lbe != NULL) {
+ return lbe;
+ }
+
+ if (needsInit) {
+ UStack *engines = new UStack(_deleteEngine, NULL, status);
+ if (U_SUCCESS(status) && engines == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else if (U_FAILURE(status)) {
+ delete engines;
+ engines = NULL;
+ }
+ else {
+ umtx_lock(NULL);
+ if (fEngines == NULL) {
+ fEngines = engines;
+ engines = NULL;
+ }
+ umtx_unlock(NULL);
+ delete engines;
+ }
+ }
+
+ if (fEngines == NULL) {
+ return NULL;
+ }
+
+ // We didn't find an engine the first time through, or there was no
+ // stack. Create an engine.
+ const LanguageBreakEngine *newlbe = loadEngineFor(c, breakType);
+
+ // Now get the lock, and see if someone else has created it in the
+ // meantime
+ umtx_lock(NULL);
+ i = fEngines->size();
+ while (--i >= 0) {
+ lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i));
+ if (lbe != NULL && lbe->handles(c, breakType)) {
+ break;
+ }
+ lbe = NULL;
+ }
+ if (lbe == NULL && newlbe != NULL) {
+ fEngines->push((void *)newlbe, status);
+ lbe = newlbe;
+ newlbe = NULL;
+ }
+ umtx_unlock(NULL);
+
+ delete newlbe;
+
+ return lbe;
+}
+
+const LanguageBreakEngine *
+ICULanguageBreakFactory::loadEngineFor(UChar32 c, int32_t breakType) {
+ UErrorCode status = U_ZERO_ERROR;
+ UScriptCode code = uscript_getScript(c, &status);
+ if (U_SUCCESS(status)) {
+ const CompactTrieDictionary *dict = loadDictionaryFor(code, breakType);
+ if (dict != NULL) {
+ const LanguageBreakEngine *engine = NULL;
+ switch(code) {
+ case USCRIPT_THAI:
+ engine = new ThaiBreakEngine(dict, status);
+ break;
+ default:
+ break;
+ }
+ if (engine == NULL) {
+ delete dict;
+ }
+ else if (U_FAILURE(status)) {
+ delete engine;
+ engine = NULL;
+ }
+ return engine;
+ }
+ }
+ return NULL;
+}
+
+const CompactTrieDictionary *
+ICULanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t /*breakType*/) {
+ UErrorCode status = U_ZERO_ERROR;
+ // Open root from brkitr tree.
+ char dictnbuff[256];
+ char ext[4]={'\0'};
+
+ UResourceBundle *b = ures_open(U_ICUDATA_BRKITR, "", &status);
+ b = ures_getByKeyWithFallback(b, "dictionaries", b, &status);
+ b = ures_getByKeyWithFallback(b, uscript_getShortName(script), b, &status);
+ int32_t dictnlength = 0;
+ const UChar *dictfname = ures_getString(b, &dictnlength, &status);
+ if (U_SUCCESS(status) && (size_t)dictnlength >= sizeof(dictnbuff)) {
+ dictnlength = 0;
+ status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ if (U_SUCCESS(status) && dictfname) {
+ UChar* extStart=u_strchr(dictfname, 0x002e);
+ int len = 0;
+ if(extStart!=NULL){
+ len = extStart-dictfname;
+ u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
+ u_UCharsToChars(dictfname, dictnbuff, len);
+ }
+ dictnbuff[len]=0; // nul terminate
+ }
+ ures_close(b);
+ UDataMemory *file = udata_open(U_ICUDATA_BRKITR, ext, dictnbuff, &status);
+ if (U_SUCCESS(status)) {
+ const CompactTrieDictionary *dict = new CompactTrieDictionary(
+ file, status);
+ if (U_SUCCESS(status) && dict == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_FAILURE(status)) {
+ delete dict;
+ dict = NULL;
+ }
+ return dict;
+ }
+ return NULL;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/brkeng.h b/Build/source/libs/icu/icu-xetex/common/brkeng.h
new file mode 100644
index 00000000000..618b2aeea5f
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/brkeng.h
@@ -0,0 +1,292 @@
+/**
+ ************************************************************************************
+ * Copyright (C) 2006-2007, International Business Machines Corporation and others. *
+ * All Rights Reserved. *
+ ************************************************************************************
+ */
+
+#ifndef BRKENG_H
+#define BRKENG_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/utext.h"
+#include "unicode/uscript.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeSet;
+class UStack;
+class CompactTrieDictionary;
+
+/*******************************************************************
+ * LanguageBreakEngine
+ */
+
+/**
+ * LanguageBreakEngines implement language-specific knowledge for
+ * finding text boundaries within a run of characters belonging to a
+ * specific set. The boundaries will be of a specific kind, e.g. word,
+ * line, etc.
+ *
+ * LanguageBreakEngines should normally be implemented so as to
+ * be shared between threads without locking.
+ */
+class LanguageBreakEngine : public UMemory {
+ public:
+
+ /**
+ * Default constructor.
+ *
+ */
+ LanguageBreakEngine();
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~LanguageBreakEngine();
+
+ /**
+ * Indicate whether this engine handles a particular character for
+ * a particular kind of break.
+ *
+ * @param c A character which begins a run that the engine might handle
+ * @param breakType The type of text break which the caller wants to determine
+ * @return TRUE if this engine handles the particular character and break
+ * type.
+ */
+ virtual UBool handles(UChar32 c, int32_t breakType) const = 0;
+
+ /**
+ * Find any breaks within a run in the supplied text.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left at the end of the run of characters which the engine
+ * is capable of handling.
+ * @param startPos The start of the run within the supplied text.
+ * @param endPos The end of the run within the supplied text.
+ * @param reverse Whether the caller is looking for breaks in a reverse
+ * direction.
+ * @param breakType The type of break desired, or -1.
+ * @param foundBreaks An allocated C array of the breaks found, if any
+ * @return The number of breaks found.
+ */
+ virtual int32_t findBreaks( UText *text,
+ int32_t startPos,
+ int32_t endPos,
+ UBool reverse,
+ int32_t breakType,
+ UStack &foundBreaks ) const = 0;
+
+};
+
+/*******************************************************************
+ * LanguageBreakFactory
+ */
+
+/**
+ * LanguageBreakFactorys find and return a LanguageBreakEngine
+ * that can determine breaks for characters in a specific set, if
+ * such an object can be found.
+ *
+ * If a LanguageBreakFactory is to be shared between threads,
+ * appropriate synchronization must be used; there is none internal
+ * to the factory.
+ *
+ * A LanguageBreakEngine returned by a LanguageBreakFactory can
+ * normally be shared between threads without synchronization, unless
+ * the specific subclass of LanguageBreakFactory indicates otherwise.
+ *
+ * A LanguageBreakFactory is responsible for deleting any LanguageBreakEngine
+ * it returns when it itself is deleted, unless the specific subclass of
+ * LanguageBreakFactory indicates otherwise. Naturally, the factory should
+ * not be deleted until the LanguageBreakEngines it has returned are no
+ * longer needed.
+ */
+class LanguageBreakFactory : public UMemory {
+ public:
+
+ /**
+ * Default constructor.
+ *
+ */
+ LanguageBreakFactory();
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~LanguageBreakFactory();
+
+ /**
+ * Find and return a LanguageBreakEngine that can find the desired
+ * kind of break for the set of characters to which the supplied
+ * character belongs. It is up to the set of available engines to
+ * determine what the sets of characters are.
+ *
+ * @param c A character that begins a run for which a LanguageBreakEngine is
+ * sought.
+ * @param breakType The kind of text break for which a LanguageBreakEngine is
+ * sought.
+ * @return A LanguageBreakEngine with the desired characteristics, or 0.
+ */
+ virtual const LanguageBreakEngine *getEngineFor(UChar32 c, int32_t breakType) = 0;
+
+};
+
+/*******************************************************************
+ * UnhandledEngine
+ */
+
+/**
+ * UnhandledEngine is a special subclass of LanguageBreakEngine that
+ * handles characters that no other LanguageBreakEngine is available to
+ * handle. It is told the character and the type of break; at its
+ * discretion it may handle more than the specified character (e.g.,
+ * the entire script to which that character belongs.
+ *
+ * UnhandledEngines may not be shared between threads without
+ * external synchronization.
+ */
+
+class UnhandledEngine : public LanguageBreakEngine {
+ private:
+
+ /**
+ * The sets of characters handled, for each break type
+ * @internal
+ */
+
+ UnicodeSet *fHandled[4];
+
+ public:
+
+ /**
+ * Default constructor.
+ *
+ */
+ UnhandledEngine(UErrorCode &status);
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~UnhandledEngine();
+
+ /**
+ * Indicate whether this engine handles a particular character for
+ * a particular kind of break.
+ *
+ * @param c A character which begins a run that the engine might handle
+ * @param breakType The type of text break which the caller wants to determine
+ * @return TRUE if this engine handles the particular character and break
+ * type.
+ */
+ virtual UBool handles(UChar32 c, int32_t breakType) const;
+
+ /**
+ * Find any breaks within a run in the supplied text.
+ *
+ * @param text A UText representing the text (TODO: UText). The
+ * iterator is left at the end of the run of characters which the engine
+ * is capable of handling.
+ * @param startPos The start of the run within the supplied text.
+ * @param endPos The end of the run within the supplied text.
+ * @param reverse Whether the caller is looking for breaks in a reverse
+ * direction.
+ * @param breakType The type of break desired, or -1.
+ * @param foundBreaks An allocated C array of the breaks found, if any
+ * @return The number of breaks found.
+ */
+ virtual int32_t findBreaks( UText *text,
+ int32_t startPos,
+ int32_t endPos,
+ UBool reverse,
+ int32_t breakType,
+ UStack &foundBreaks ) const;
+
+ /**
+ * Tell the engine to handle a particular character and break type.
+ *
+ * @param c A character which the engine should handle
+ * @param breakType The type of text break for which the engine should handle c
+ */
+ virtual void handleCharacter(UChar32 c, int32_t breakType);
+
+};
+
+/*******************************************************************
+ * ICULanguageBreakFactory
+ */
+
+/**
+ * ICULanguageBreakFactory is the default LanguageBreakFactory for
+ * ICU. It creates dictionary-based LanguageBreakEngines from dictionary
+ * data in the ICU data file.
+ */
+class ICULanguageBreakFactory : public LanguageBreakFactory {
+ private:
+
+ /**
+ * The stack of break engines created by this factory
+ * @internal
+ */
+
+ UStack *fEngines;
+
+ public:
+
+ /**
+ * Standard constructor.
+ *
+ */
+ ICULanguageBreakFactory(UErrorCode &status);
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~ICULanguageBreakFactory();
+
+ /**
+ * Find and return a LanguageBreakEngine that can find the desired
+ * kind of break for the set of characters to which the supplied
+ * character belongs. It is up to the set of available engines to
+ * determine what the sets of characters are.
+ *
+ * @param c A character that begins a run for which a LanguageBreakEngine is
+ * sought.
+ * @param breakType The kind of text break for which a LanguageBreakEngine is
+ * sought.
+ * @return A LanguageBreakEngine with the desired characteristics, or 0.
+ */
+ virtual const LanguageBreakEngine *getEngineFor(UChar32 c, int32_t breakType);
+
+ protected:
+
+ /**
+ * Create a LanguageBreakEngine for the set of characters to which
+ * the supplied character belongs, for the specified break type.
+ *
+ * @param c A character that begins a run for which a LanguageBreakEngine is
+ * sought.
+ * @param breakType The kind of text break for which a LanguageBreakEngine is
+ * sought.
+ * @return A LanguageBreakEngine with the desired characteristics, or 0.
+ */
+ virtual const LanguageBreakEngine *loadEngineFor(UChar32 c, int32_t breakType);
+
+ /**
+ * Create a CompactTrieDictionary for the specified script and break type.
+ *
+ * @param script An ISO 15924 script code that identifies the dictionary to be
+ * created.
+ * @param breakType The kind of text break for which a dictionary is
+ * sought.
+ * @return A CompactTrieDictionary with the desired characteristics, or 0.
+ */
+ virtual const CompactTrieDictionary *loadDictionaryFor(UScriptCode script, int32_t breakType);
+
+};
+
+U_NAMESPACE_END
+
+ /* BRKENG_H */
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/brkiter.cpp b/Build/source/libs/icu/icu-xetex/common/brkiter.cpp
new file mode 100644
index 00000000000..3bfc13adee2
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/brkiter.cpp
@@ -0,0 +1,454 @@
+/*
+*******************************************************************************
+* Copyright (C) 1997-2007, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File TXTBDRY.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/18/97 aliu Converted from OpenClass. Added DONE.
+* 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods.
+*****************************************************************************************
+*/
+
+// *****************************************************************************
+// This file was generated from the java source file BreakIterator.java
+// *****************************************************************************
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/rbbi.h"
+#include "unicode/brkiter.h"
+#include "unicode/udata.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "ucln_cmn.h"
+#include "cstring.h"
+#include "umutex.h"
+#include "servloc.h"
+#include "locbased.h"
+#include "uresimp.h"
+#include "uassert.h"
+#include "ubrkimpl.h"
+
+// *****************************************************************************
+// class BreakIterator
+// This class implements methods for finding the location of boundaries in text.
+// Instances of BreakIterator maintain a current position and scan over text
+// returning the index of characters where boundaries occur.
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+// -------------------------------------
+
+BreakIterator*
+BreakIterator::buildInstance(const Locale& loc, const char *type, int32_t kind, UErrorCode &status)
+{
+ char fnbuff[256];
+ char ext[4]={'\0'};
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+ int32_t size;
+ const UChar* brkfname = NULL;
+ UResourceBundle brkRulesStack;
+ UResourceBundle brkNameStack;
+ UResourceBundle *brkRules = &brkRulesStack;
+ UResourceBundle *brkName = &brkNameStack;
+ RuleBasedBreakIterator *result = NULL;
+
+ if (U_FAILURE(status))
+ return NULL;
+
+ ures_initStackObject(brkRules);
+ ures_initStackObject(brkName);
+
+ // Get the locale
+ UResourceBundle *b = ures_open(U_ICUDATA_BRKITR, loc.getName(), &status);
+ /* this is a hack for now. Should be fixed when the data is fetched from
+ brk_index.txt */
+ if(status==U_USING_DEFAULT_WARNING){
+ status=U_ZERO_ERROR;
+ ures_openFillIn(b, U_ICUDATA_BRKITR, "", &status);
+ }
+
+ // Get the "boundaries" array.
+ if (U_SUCCESS(status)) {
+ brkRules = ures_getByKeyWithFallback(b, "boundaries", brkRules, &status);
+ // Get the string object naming the rules file
+ brkName = ures_getByKeyWithFallback(brkRules, type, brkName, &status);
+ // Get the actual string
+ brkfname = ures_getString(brkName, &size, &status);
+ U_ASSERT((size_t)size=sizeof(fnbuff)) {
+ size=0;
+ if (U_SUCCESS(status)) {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+
+ // Use the string if we found it
+ if (U_SUCCESS(status) && brkfname) {
+ uprv_strncpy(actualLocale,
+ ures_getLocale(brkName, &status),
+ sizeof(actualLocale)/sizeof(actualLocale[0]));
+
+ UChar* extStart=u_strchr(brkfname, 0x002e);
+ int len = 0;
+ if(extStart!=NULL){
+ len = extStart-brkfname;
+ u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
+ u_UCharsToChars(brkfname, fnbuff, len);
+ }
+ fnbuff[len]=0; // nul terminate
+ }
+ }
+
+ ures_close(brkRules);
+ ures_close(brkName);
+
+ UDataMemory* file = udata_open(U_ICUDATA_BRKITR, ext, fnbuff, &status);
+ if (U_FAILURE(status)) {
+ ures_close(b);
+ return NULL;
+ }
+
+ // Create a RuleBasedBreakIterator
+ result = new RuleBasedBreakIterator(file, status);
+
+ // If there is a result, set the valid locale and actual locale, and the kind
+ if (U_SUCCESS(status) && result != NULL) {
+ U_LOCALE_BASED(locBased, *(BreakIterator*)result);
+ locBased.setLocaleIDs(ures_getLocaleByType(b, ULOC_VALID_LOCALE, &status), actualLocale);
+ result->setBreakType(kind);
+ }
+
+ ures_close(b);
+
+ if (U_FAILURE(status) && result != NULL) { // Sometimes redundant check, but simple
+ delete result;
+ return NULL;
+ }
+
+ if (result == NULL) {
+ udata_close(file);
+ if (U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+
+ return result;
+}
+
+// Creates a break iterator for word breaks.
+BreakIterator* U_EXPORT2
+BreakIterator::createWordInstance(const Locale& key, UErrorCode& status)
+{
+ return createInstance(key, UBRK_WORD, status);
+}
+
+// -------------------------------------
+
+// Creates a break iterator for line breaks.
+BreakIterator* U_EXPORT2
+BreakIterator::createLineInstance(const Locale& key, UErrorCode& status)
+{
+ return createInstance(key, UBRK_LINE, status);
+}
+
+// -------------------------------------
+
+// Creates a break iterator for character breaks.
+BreakIterator* U_EXPORT2
+BreakIterator::createCharacterInstance(const Locale& key, UErrorCode& status)
+{
+ return createInstance(key, UBRK_CHARACTER, status);
+}
+
+// -------------------------------------
+
+// Creates a break iterator for sentence breaks.
+BreakIterator* U_EXPORT2
+BreakIterator::createSentenceInstance(const Locale& key, UErrorCode& status)
+{
+ return createInstance(key, UBRK_SENTENCE, status);
+}
+
+// -------------------------------------
+
+// Creates a break iterator for title casing breaks.
+BreakIterator* U_EXPORT2
+BreakIterator::createTitleInstance(const Locale& key, UErrorCode& status)
+{
+ return createInstance(key, UBRK_TITLE, status);
+}
+
+// -------------------------------------
+
+// Gets all the available locales that has localized text boundary data.
+const Locale* U_EXPORT2
+BreakIterator::getAvailableLocales(int32_t& count)
+{
+ return Locale::getAvailableLocales(count);
+}
+
+// -------------------------------------
+// Gets the objectLocale display name in the default locale language.
+UnicodeString& U_EXPORT2
+BreakIterator::getDisplayName(const Locale& objectLocale,
+ UnicodeString& name)
+{
+ return objectLocale.getDisplayName(name);
+}
+
+// -------------------------------------
+// Gets the objectLocale display name in the displayLocale language.
+UnicodeString& U_EXPORT2
+BreakIterator::getDisplayName(const Locale& objectLocale,
+ const Locale& displayLocale,
+ UnicodeString& name)
+{
+ return objectLocale.getDisplayName(displayLocale, name);
+}
+
+// ------------------------------------------
+//
+// Default constructor and destructor
+//
+//-------------------------------------------
+
+BreakIterator::BreakIterator()
+{
+ fBufferClone = FALSE;
+ *validLocale = *actualLocale = 0;
+}
+
+BreakIterator::~BreakIterator()
+{
+}
+
+// ------------------------------------------
+//
+// Registration
+//
+//-------------------------------------------
+#if !UCONFIG_NO_SERVICE
+
+// -------------------------------------
+
+class ICUBreakIteratorFactory : public ICUResourceBundleFactory {
+protected:
+ virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* /*service*/, UErrorCode& status) const {
+ return BreakIterator::makeInstance(loc, kind, status);
+ }
+};
+
+// -------------------------------------
+
+class ICUBreakIteratorService : public ICULocaleService {
+public:
+ ICUBreakIteratorService()
+ : ICULocaleService(UNICODE_STRING("Break Iterator", 14))
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ registerFactory(new ICUBreakIteratorFactory(), status);
+ }
+
+ virtual UObject* cloneInstance(UObject* instance) const {
+ return ((BreakIterator*)instance)->clone();
+ }
+
+ virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /*actualID*/, UErrorCode& status) const {
+ LocaleKey& lkey = (LocaleKey&)key;
+ int32_t kind = lkey.kind();
+ Locale loc;
+ lkey.currentLocale(loc);
+ return BreakIterator::makeInstance(loc, kind, status);
+ }
+
+ virtual UBool isDefault() const {
+ return countFactories() == 1;
+ }
+};
+
+// -------------------------------------
+
+U_NAMESPACE_END
+
+// defined in ucln_cmn.h
+
+static U_NAMESPACE_QUALIFIER ICULocaleService* gService = NULL;
+
+/**
+ * Release all static memory held by breakiterator.
+ */
+U_CDECL_BEGIN
+static UBool U_CALLCONV breakiterator_cleanup(void) {
+#if !UCONFIG_NO_SERVICE
+ if (gService) {
+ delete gService;
+ gService = NULL;
+ }
+#endif
+ return TRUE;
+}
+U_CDECL_END
+U_NAMESPACE_BEGIN
+
+static ICULocaleService*
+getService(void)
+{
+ UBool needsInit;
+ UMTX_CHECK(NULL, (UBool)(gService == NULL), needsInit);
+
+ if (needsInit) {
+ ICULocaleService *tService = new ICUBreakIteratorService();
+ umtx_lock(NULL);
+ if (gService == NULL) {
+ gService = tService;
+ tService = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_BREAKITERATOR, breakiterator_cleanup);
+ }
+ umtx_unlock(NULL);
+ delete tService;
+ }
+ return gService;
+}
+
+// -------------------------------------
+
+static inline UBool
+hasService(void)
+{
+ UBool retVal;
+ UMTX_CHECK(NULL, gService != NULL, retVal);
+ return retVal;
+}
+
+// -------------------------------------
+
+URegistryKey U_EXPORT2
+BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
+{
+ return getService()->registerInstance(toAdopt, locale, kind, status);
+}
+
+// -------------------------------------
+
+UBool U_EXPORT2
+BreakIterator::unregister(URegistryKey key, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if (hasService()) {
+ return gService->unregister(key, status);
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return FALSE;
+}
+
+// -------------------------------------
+
+StringEnumeration* U_EXPORT2
+BreakIterator::getAvailableLocales(void)
+{
+ return getService()->getAvailableLocales();
+}
+#endif /* UCONFIG_NO_SERVICE */
+
+// -------------------------------------
+
+BreakIterator*
+BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ u_init(&status);
+#if !UCONFIG_NO_SERVICE
+ if (hasService()) {
+ Locale actualLoc("");
+ BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &actualLoc, status);
+ // TODO: The way the service code works in ICU 2.8 is that if
+ // there is a real registered break iterator, the actualLoc
+ // will be populated, but if the handleDefault path is taken
+ // (because nothing is registered that can handle the
+ // requested locale) then the actualLoc comes back empty. In
+ // that case, the returned object already has its actual/valid
+ // locale data populated (by makeInstance, which is what
+ // handleDefault calls), so we don't touch it. YES, A COMMENT
+ // THIS LONG is a sign of bad code -- so the action item is to
+ // revisit this in ICU 3.0 and clean it up/fix it/remove it.
+ if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) {
+ U_LOCALE_BASED(locBased, *result);
+ locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName());
+ }
+ return result;
+ }
+ else
+#endif
+ {
+ return makeInstance(loc, kind, status);
+ }
+}
+
+// -------------------------------------
+
+BreakIterator*
+BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
+{
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ BreakIterator *result = NULL;
+ switch (kind) {
+ case UBRK_CHARACTER:
+ result = BreakIterator::buildInstance(loc, "grapheme", kind, status);
+ break;
+ case UBRK_WORD:
+ result = BreakIterator::buildInstance(loc, "word", kind, status);
+ break;
+ case UBRK_LINE:
+ result = BreakIterator::buildInstance(loc, "line", kind, status);
+ break;
+ case UBRK_SENTENCE:
+ result = BreakIterator::buildInstance(loc, "sentence", kind, status);
+ break;
+ case UBRK_TITLE:
+ result = BreakIterator::buildInstance(loc, "title", kind, status);
+ break;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ return result;
+}
+
+Locale
+BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocale(type, status);
+}
+
+const char *
+BreakIterator::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocaleID(type, status);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
+
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/caniter.cpp b/Build/source/libs/icu/icu-xetex/common/caniter.cpp
new file mode 100644
index 00000000000..04d48ba8fce
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/caniter.cpp
@@ -0,0 +1,611 @@
+/*
+ *****************************************************************************
+ * Copyright (C) 1996-2006, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *****************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+#include "unicode/uset.h"
+#include "unicode/ustring.h"
+#include "hash.h"
+#include "unormimp.h"
+#include "unicode/caniter.h"
+#include "unicode/normlzr.h"
+#include "unicode/uchar.h"
+#include "cmemory.h"
+
+/**
+ * This class allows one to iterate through all the strings that are canonically equivalent to a given
+ * string. For example, here are some sample results:
+Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
+1: \u0041\u030A\u0064\u0307\u0327
+ = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
+2: \u0041\u030A\u0064\u0327\u0307
+ = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
+3: \u0041\u030A\u1E0B\u0327
+ = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
+4: \u0041\u030A\u1E11\u0307
+ = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
+5: \u00C5\u0064\u0307\u0327
+ = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
+6: \u00C5\u0064\u0327\u0307
+ = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
+7: \u00C5\u1E0B\u0327
+ = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
+8: \u00C5\u1E11\u0307
+ = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
+9: \u212B\u0064\u0307\u0327
+ = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
+10: \u212B\u0064\u0327\u0307
+ = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
+11: \u212B\u1E0B\u0327
+ = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
+12: \u212B\u1E11\u0307
+ = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
+ *
Note: the code is intended for use with small strings, and is not suitable for larger ones,
+ * since it has not been optimized for that situation.
+ *@author M. Davis
+ *@draft
+ */
+
+// public
+
+U_NAMESPACE_BEGIN
+
+// TODO: add boilerplate methods.
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CanonicalIterator)
+
+/**
+ *@param source string to get results for
+ */
+CanonicalIterator::CanonicalIterator(const UnicodeString &sourceStr, UErrorCode &status) :
+ pieces(NULL),
+ pieces_length(0),
+ pieces_lengths(NULL),
+ current(NULL),
+ current_length(0)
+{
+ if(U_SUCCESS(status)) {
+ setSource(sourceStr, status);
+ }
+}
+
+CanonicalIterator::~CanonicalIterator() {
+ cleanPieces();
+}
+
+void CanonicalIterator::cleanPieces() {
+ int32_t i = 0;
+ if(pieces != NULL) {
+ for(i = 0; i < pieces_length; i++) {
+ if(pieces[i] != NULL) {
+ delete[] pieces[i];
+ }
+ }
+ uprv_free(pieces);
+ pieces = NULL;
+ pieces_length = 0;
+ }
+ if(pieces_lengths != NULL) {
+ uprv_free(pieces_lengths);
+ pieces_lengths = NULL;
+ }
+ if(current != NULL) {
+ uprv_free(current);
+ current = NULL;
+ current_length = 0;
+ }
+}
+
+/**
+ *@return gets the source: NOTE: it is the NFD form of source
+ */
+UnicodeString CanonicalIterator::getSource() {
+ return source;
+}
+
+/**
+ * Resets the iterator so that one can start again from the beginning.
+ */
+void CanonicalIterator::reset() {
+ done = FALSE;
+ for (int i = 0; i < current_length; ++i) {
+ current[i] = 0;
+ }
+}
+
+/**
+ *@return the next string that is canonically equivalent. The value null is returned when
+ * the iteration is done.
+ */
+UnicodeString CanonicalIterator::next() {
+ int32_t i = 0;
+
+ if (done) {
+ buffer.setToBogus();
+ return buffer;
+ }
+
+ // delete old contents
+ buffer.remove();
+
+ // construct return value
+
+ for (i = 0; i < pieces_length; ++i) {
+ buffer.append(pieces[i][current[i]]);
+ }
+ //String result = buffer.toString(); // not needed
+
+ // find next value for next time
+
+ for (i = current_length - 1; ; --i) {
+ if (i < 0) {
+ done = TRUE;
+ break;
+ }
+ current[i]++;
+ if (current[i] < pieces_lengths[i]) break; // got sequence
+ current[i] = 0;
+ }
+ return buffer;
+}
+
+/**
+ *@param set the source string to iterate against. This allows the same iterator to be used
+ * while changing the source string, saving object creation.
+ */
+void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &status) {
+ int32_t list_length = 0;
+ UChar32 cp = 0;
+ int32_t start = 0;
+ int32_t i = 0;
+ UnicodeString *list = NULL;
+
+ Normalizer::normalize(newSource, UNORM_NFD, 0, source, status);
+ if(U_FAILURE(status)) {
+ return;
+ }
+ done = FALSE;
+
+ cleanPieces();
+
+ // catch degenerate case
+ if (newSource.length() == 0) {
+ pieces = (UnicodeString **)uprv_malloc(sizeof(UnicodeString *));
+ pieces_lengths = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
+ pieces_length = 1;
+ current = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
+ current_length = 1;
+ if (pieces == NULL || pieces_lengths == NULL || current == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto CleanPartialInitialization;
+ }
+ current[0] = 0;
+ pieces[0] = new UnicodeString[1];
+ pieces_lengths[0] = 1;
+ if (pieces[0] == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto CleanPartialInitialization;
+ }
+ return;
+ }
+
+
+ list = new UnicodeString[source.length()];
+ if (list == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto CleanPartialInitialization;
+ }
+
+ // i should initialy be the number of code units at the
+ // start of the string
+ i = UTF16_CHAR_LENGTH(source.char32At(0));
+ //int32_t i = 1;
+ // find the segments
+ // This code iterates through the source string and
+ // extracts segments that end up on a codepoint that
+ // doesn't start any decompositions. (Analysis is done
+ // on the NFD form - see above).
+ for (; i < source.length(); i += UTF16_CHAR_LENGTH(cp)) {
+ cp = source.char32At(i);
+ if (unorm_isCanonSafeStart(cp)) {
+ source.extract(start, i-start, list[list_length++]); // add up to i
+ start = i;
+ }
+ }
+ source.extract(start, i-start, list[list_length++]); // add last one
+
+
+ // allocate the arrays, and find the strings that are CE to each segment
+ pieces = (UnicodeString **)uprv_malloc(list_length * sizeof(UnicodeString *));
+ pieces_length = list_length;
+ pieces_lengths = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
+ current = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
+ current_length = list_length;
+ if (pieces == NULL || pieces_lengths == NULL || current == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto CleanPartialInitialization;
+ }
+
+ for (i = 0; i < current_length; i++) {
+ current[i] = 0;
+ }
+ // for each segment, get all the combinations that can produce
+ // it after NFD normalization
+ for (i = 0; i < pieces_length; ++i) {
+ //if (PROGRESS) printf("SEGMENT\n");
+ pieces[i] = getEquivalents(list[i], pieces_lengths[i], status);
+ }
+
+ delete[] list;
+ return;
+// Common section to cleanup all local variables and reset object variables.
+CleanPartialInitialization:
+ if (list != NULL) {
+ delete[] list;
+ }
+ cleanPieces();
+}
+
+/**
+ * Dumb recursive implementation of permutation.
+ * TODO: optimize
+ * @param source the string to find permutations for
+ * @return the results in a set.
+ */
+void U_EXPORT2 CanonicalIterator::permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status) {
+ if(U_FAILURE(status)) {
+ return;
+ }
+ //if (PROGRESS) printf("Permute: %s\n", UToS(Tr(source)));
+ int32_t i = 0;
+
+ // optimization:
+ // if zero or one character, just return a set with it
+ // we check for length < 2 to keep from counting code points all the time
+ if (source.length() <= 2 && source.countChar32() <= 1) {
+ UnicodeString *toPut = new UnicodeString(source);
+ /* test for NULL */
+ if (toPut == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ result->put(source, toPut, status);
+ return;
+ }
+
+ // otherwise iterate through the string, and recursively permute all the other characters
+ UChar32 cp;
+ Hashtable subpermute(status);
+ if(U_FAILURE(status)) {
+ return;
+ }
+ subpermute.setValueDeleter(uhash_deleteUnicodeString);
+
+ for (i = 0; i < source.length(); i += UTF16_CHAR_LENGTH(cp)) {
+ cp = source.char32At(i);
+ const UHashElement *ne = NULL;
+ int32_t el = -1;
+ UnicodeString subPermuteString = source;
+
+ // optimization:
+ // if the character is canonical combining class zero,
+ // don't permute it
+ if (skipZeros && i != 0 && u_getCombiningClass(cp) == 0) {
+ //System.out.println("Skipping " + Utility.hex(UTF16.valueOf(source, i)));
+ continue;
+ }
+
+ subpermute.removeAll();
+
+ // see what the permutations of the characters before and after this one are
+ //Hashtable *subpermute = permute(source.substring(0,i) + source.substring(i + UTF16.getCharCount(cp)));
+ permute(subPermuteString.replace(i, UTF16_CHAR_LENGTH(cp), NULL, 0), skipZeros, &subpermute, status);
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return;
+ }
+ // The upper replace is destructive. The question is do we have to make a copy, or we don't care about the contents
+ // of source at this point.
+
+ // prefix this character to all of them
+ ne = subpermute.nextElement(el);
+ while (ne != NULL) {
+ UnicodeString *permRes = (UnicodeString *)(ne->value.pointer);
+ UnicodeString *chStr = new UnicodeString(cp);
+ //test for NULL
+ if (chStr == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ chStr->append(*permRes); //*((UnicodeString *)(ne->value.pointer));
+ //if (PROGRESS) printf(" Piece: %s\n", UToS(*chStr));
+ result->put(*chStr, chStr, status);
+ ne = subpermute.nextElement(el);
+ }
+ }
+ //return result;
+}
+
+// privates
+
+// we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
+UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status) {
+ Hashtable result(status);
+ Hashtable permutations(status);
+ Hashtable basic(status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ result.setValueDeleter(uhash_deleteUnicodeString);
+ permutations.setValueDeleter(uhash_deleteUnicodeString);
+ basic.setValueDeleter(uhash_deleteUnicodeString);
+
+ UChar USeg[256];
+ int32_t segLen = segment.extract(USeg, 256, status);
+ getEquivalents2(&basic, USeg, segLen, status);
+
+ // now get all the permutations
+ // add only the ones that are canonically equivalent
+ // TODO: optimize by not permuting any class zero.
+
+ const UHashElement *ne = NULL;
+ int32_t el = -1;
+ //Iterator it = basic.iterator();
+ ne = basic.nextElement(el);
+ //while (it.hasNext())
+ while (ne != NULL) {
+ //String item = (String) it.next();
+ UnicodeString item = *((UnicodeString *)(ne->value.pointer));
+
+ permutations.removeAll();
+ permute(item, CANITER_SKIP_ZEROES, &permutations, status);
+ const UHashElement *ne2 = NULL;
+ int32_t el2 = -1;
+ //Iterator it2 = permutations.iterator();
+ ne2 = permutations.nextElement(el2);
+ //while (it2.hasNext())
+ while (ne2 != NULL) {
+ //String possible = (String) it2.next();
+ //UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne2->value.pointer)));
+ UnicodeString possible(*((UnicodeString *)(ne2->value.pointer)));
+ UnicodeString attempt;
+ Normalizer::normalize(possible, UNORM_NFD, 0, attempt, status);
+
+ // TODO: check if operator == is semanticaly the same as attempt.equals(segment)
+ if (attempt==segment) {
+ //if (PROGRESS) printf("Adding Permutation: %s\n", UToS(Tr(*possible)));
+ // TODO: use the hashtable just to catch duplicates - store strings directly (somehow).
+ result.put(possible, new UnicodeString(possible), status); //add(possible);
+ } else {
+ //if (PROGRESS) printf("-Skipping Permutation: %s\n", UToS(Tr(*possible)));
+ }
+
+ ne2 = permutations.nextElement(el2);
+ }
+ ne = basic.nextElement(el);
+ }
+
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+ // convert into a String[] to clean up storage
+ //String[] finalResult = new String[result.size()];
+ UnicodeString *finalResult = NULL;
+ int32_t resultCount;
+ if((resultCount = result.count())) {
+ finalResult = new UnicodeString[resultCount];
+ if (finalResult == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ }
+ else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ //result.toArray(finalResult);
+ result_len = 0;
+ el = -1;
+ ne = result.nextElement(el);
+ while(ne != NULL) {
+ finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer));
+ ne = result.nextElement(el);
+ }
+
+
+ return finalResult;
+}
+
+Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const UChar *segment, int32_t segLen, UErrorCode &status) {
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ //if (PROGRESS) printf("Adding: %s\n", UToS(Tr(segment)));
+
+ UnicodeString toPut(segment, segLen);
+
+ fillinResult->put(toPut, new UnicodeString(toPut), status);
+
+ USerializedSet starts;
+
+ // cycle through all the characters
+ UChar32 cp, end = 0;
+ int32_t i = 0, j;
+ for (i = 0; i < segLen; i += UTF16_CHAR_LENGTH(cp)) {
+ // see if any character is at the start of some decomposition
+ UTF_GET_CHAR(segment, 0, i, segLen, cp);
+ if (!unorm_getCanonStartSet(cp, &starts)) {
+ continue;
+ }
+ // if so, see which decompositions match
+ for(j = 0, cp = end+1; cp <= end || uset_getSerializedRange(&starts, j++, &cp, &end); ++cp) {
+ Hashtable remainder(status);
+ remainder.setValueDeleter(uhash_deleteUnicodeString);
+ if (extract(&remainder, cp, segment, segLen, i, status) == NULL) {
+ continue;
+ }
+
+ // there were some matches, so add all the possibilities to the set.
+ UnicodeString prefix(segment, i);
+ prefix += cp;
+
+ int32_t el = -1;
+ const UHashElement *ne = remainder.nextElement(el);
+ while (ne != NULL) {
+ UnicodeString item = *((UnicodeString *)(ne->value.pointer));
+ UnicodeString *toAdd = new UnicodeString(prefix);
+ /* test for NULL */
+ if (toAdd == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ *toAdd += item;
+ fillinResult->put(*toAdd, toAdd, status);
+
+ //if (PROGRESS) printf("Adding: %s\n", UToS(Tr(*toAdd)));
+
+ ne = remainder.nextElement(el);
+ }
+ }
+ }
+
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return NULL;
+ }
+ return fillinResult;
+}
+
+/**
+ * See if the decomposition of cp2 is at segment starting at segmentPos
+ * (with canonical rearrangment!)
+ * If so, take the remainder, and return the equivalents
+ */
+Hashtable *CanonicalIterator::extract(Hashtable *fillinResult, UChar32 comp, const UChar *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status) {
+//Hashtable *CanonicalIterator::extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status) {
+ //if (PROGRESS) printf(" extract: %s, ", UToS(Tr(UnicodeString(comp))));
+ //if (PROGRESS) printf("%s, %i\n", UToS(Tr(segment)), segmentPos);
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const int32_t bufSize = 256;
+ int32_t bufLen = 0;
+ UChar temp[bufSize];
+
+ int32_t inputLen = 0, decompLen;
+ UChar stackBuffer[4];
+ const UChar *decomp;
+
+ U16_APPEND_UNSAFE(temp, inputLen, comp);
+ decomp = unorm_getCanonicalDecomposition(comp, stackBuffer, &decompLen);
+ if(decomp == NULL) {
+ /* copy temp */
+ stackBuffer[0] = temp[0];
+ if(inputLen > 1) {
+ stackBuffer[1] = temp[1];
+ }
+ decomp = stackBuffer;
+ decompLen = inputLen;
+ }
+
+ UChar *buff = temp+inputLen;
+
+ // See if it matches the start of segment (at segmentPos)
+ UBool ok = FALSE;
+ UChar32 cp;
+ int32_t decompPos = 0;
+ UChar32 decompCp;
+ UTF_NEXT_CHAR(decomp, decompPos, decompLen, decompCp);
+
+ int32_t i;
+ UBool overflow = FALSE;
+
+ i = segmentPos;
+ while(i < segLen) {
+ UTF_NEXT_CHAR(segment, i, segLen, cp);
+
+ if (cp == decompCp) { // if equal, eat another cp from decomp
+
+ //if (PROGRESS) printf(" matches: %s\n", UToS(Tr(UnicodeString(cp))));
+
+ if (decompPos == decompLen) { // done, have all decomp characters!
+ //u_strcat(buff+bufLen, segment+i);
+ uprv_memcpy(buff+bufLen, segment+i, (segLen-i)*sizeof(UChar));
+ bufLen+=segLen-i;
+
+ ok = TRUE;
+ break;
+ }
+ UTF_NEXT_CHAR(decomp, decompPos, decompLen, decompCp);
+ } else {
+ //if (PROGRESS) printf(" buffer: %s\n", UToS(Tr(UnicodeString(cp))));
+
+ // brute force approach
+
+ U16_APPEND(buff, bufLen, bufSize, cp, overflow);
+
+ if(overflow) {
+ /*
+ * ### TODO handle buffer overflow
+ * The buffer is large, but an overflow may still happen with
+ * unusual input (many combining marks?).
+ * Reallocate buffer and continue.
+ * markus 20020929
+ */
+
+ overflow = FALSE;
+ }
+
+ /* TODO: optimize
+ // since we know that the classes are monotonically increasing, after zero
+ // e.g. 0 5 7 9 0 3
+ // we can do an optimization
+ // there are only a few cases that work: zero, less, same, greater
+ // if both classes are the same, we fail
+ // if the decomp class < the segment class, we fail
+
+ segClass = getClass(cp);
+ if (decompClass <= segClass) return null;
+ */
+ }
+ }
+ if (!ok)
+ return NULL; // we failed, characters left over
+
+ //if (PROGRESS) printf("Matches\n");
+
+ if (bufLen == 0) {
+ fillinResult->put(UnicodeString(), new UnicodeString(), status);
+ return fillinResult; // succeed, but no remainder
+ }
+
+ // brute force approach
+ // check to make sure result is canonically equivalent
+ int32_t tempLen = inputLen + bufLen;
+
+ UChar trial[bufSize];
+ unorm_decompose(trial, bufSize, temp, tempLen, FALSE, 0, &status);
+
+ if(U_FAILURE(status)
+ || uprv_memcmp(segment+segmentPos, trial, (segLen - segmentPos)*sizeof(UChar)) != 0)
+ {
+ return NULL;
+ }
+
+ return getEquivalents2(fillinResult, buff, bufLen, status);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_NORMALIZATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/chariter.cpp b/Build/source/libs/icu/icu-xetex/common/chariter.cpp
new file mode 100644
index 00000000000..a598bd65888
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/chariter.cpp
@@ -0,0 +1,96 @@
+/*
+**********************************************************************
+* Copyright (C) 1999-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#include "unicode/chariter.h"
+
+U_NAMESPACE_BEGIN
+
+ForwardCharacterIterator::~ForwardCharacterIterator() {}
+ForwardCharacterIterator::ForwardCharacterIterator()
+: UObject()
+{}
+ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
+: UObject(other)
+{}
+
+
+CharacterIterator::CharacterIterator()
+: textLength(0), pos(0), begin(0), end(0) {
+}
+
+CharacterIterator::CharacterIterator(int32_t length)
+: textLength(length), pos(0), begin(0), end(length) {
+ if(textLength < 0) {
+ textLength = end = 0;
+ }
+}
+
+CharacterIterator::CharacterIterator(int32_t length, int32_t position)
+: textLength(length), pos(position), begin(0), end(length) {
+ if(textLength < 0) {
+ textLength = end = 0;
+ }
+ if(pos < 0) {
+ pos = 0;
+ } else if(pos > end) {
+ pos = end;
+ }
+}
+
+CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position)
+: textLength(length), pos(position), begin(textBegin), end(textEnd) {
+ if(textLength < 0) {
+ textLength = 0;
+ }
+ if(begin < 0) {
+ begin = 0;
+ } else if(begin > textLength) {
+ begin = textLength;
+ }
+ if(end < begin) {
+ end = begin;
+ } else if(end > textLength) {
+ end = textLength;
+ }
+ if(pos < begin) {
+ pos = begin;
+ } else if(pos > end) {
+ pos = end;
+ }
+}
+
+CharacterIterator::CharacterIterator(const CharacterIterator &that) :
+ForwardCharacterIterator(that),
+textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
+{
+}
+
+CharacterIterator &
+CharacterIterator::operator=(const CharacterIterator &that) {
+ ForwardCharacterIterator::operator=(that);
+ textLength = that.textLength;
+ pos = that.pos;
+ begin = that.begin;
+ end = that.end;
+ return *this;
+}
+
+// implementing first[32]PostInc() directly in a subclass should be faster
+// but these implementations make subclassing a little easier
+UChar
+CharacterIterator::firstPostInc(void) {
+ setToStart();
+ return nextPostInc();
+}
+
+UChar32
+CharacterIterator::first32PostInc(void) {
+ setToStart();
+ return next32PostInc();
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/charstr.h b/Build/source/libs/icu/icu-xetex/common/charstr.h
new file mode 100644
index 00000000000..3bb11cbad35
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/charstr.h
@@ -0,0 +1,88 @@
+/*
+**********************************************************************
+* Copyright (c) 2001-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/19/2001 aliu Creation.
+**********************************************************************
+*/
+
+#ifndef CHARSTRING_H
+#define CHARSTRING_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "cmemory.h"
+
+//--------------------------------------------------------------------
+// class CharString
+//
+// This is a tiny wrapper class that is used internally to make a
+// UnicodeString look like a const char*. It can be allocated on the
+// stack. It only creates a heap buffer if it needs to.
+//--------------------------------------------------------------------
+
+U_NAMESPACE_BEGIN
+
+class U_COMMON_API CharString : public UMemory {
+public:
+
+#if !UCONFIG_NO_CONVERSION
+ // Constructor
+ // @param str The unicode string to be converted to char *
+ // @param codepage The char * code page. "" for invariant conversion.
+ // NULL for default code page.
+// inline CharString(const UnicodeString& str, const char *codepage);
+#endif
+
+ inline CharString(const UnicodeString& str);
+ inline ~CharString();
+ inline operator const char*() const { return ptr; }
+
+private:
+ char buf[128];
+ char* ptr;
+
+ CharString(const CharString &other); // forbid copying of this class
+ CharString &operator=(const CharString &other); // forbid copying of this class
+};
+
+#if !UCONFIG_NO_CONVERSION
+
+// PLEASE DON'T USE THIS FUNCTION.
+// We don't want the static dependency on conversion or the performance hit that comes from a codepage conversion.
+/*
+inline CharString::CharString(const UnicodeString& str, const char *codepage) {
+ int32_t len;
+ ptr = buf;
+ len = str.extract(0, 0x7FFFFFFF, buf ,sizeof(buf)-1, codepage);
+ if (len >= (int32_t)(sizeof(buf)-1)) {
+ ptr = (char *)uprv_malloc(len+1);
+ str.extract(0, 0x7FFFFFFF, ptr, len+1, codepage);
+ }
+}*/
+
+#endif
+
+inline CharString::CharString(const UnicodeString& str) {
+ int32_t len;
+ ptr = buf;
+ len = str.extract(0, 0x7FFFFFFF, buf, (int32_t)(sizeof(buf)-1), US_INV);
+ if (len >= (int32_t)(sizeof(buf)-1)) {
+ ptr = (char *)uprv_malloc(len+1);
+ str.extract(0, 0x7FFFFFFF, ptr, len+1, US_INV);
+ }
+}
+
+inline CharString::~CharString() {
+ if (ptr != buf) {
+ uprv_free(ptr);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/cmemory.c b/Build/source/libs/icu/icu-xetex/common/cmemory.c
new file mode 100644
index 00000000000..0f93f36a63d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cmemory.c
@@ -0,0 +1,124 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2002-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File cmemory.c ICU Heap allocation.
+* All ICU heap allocation, both for C and C++ new of ICU
+* class types, comes through these functions.
+*
+* If you have a need to replace ICU allocation, this is the
+* place to do it.
+*
+* Note that uprv_malloc(0) returns a non-NULL pointer, and
+* that a subsequent free of that pointer value is a NOP.
+*
+******************************************************************************
+*/
+#include "unicode/uclean.h"
+#include "cmemory.h"
+#include
+
+/* uprv_malloc(0) returns a pointer to this read-only data. */
+static const int32_t zeroMem[] = {0, 0, 0, 0, 0, 0};
+
+/* Function Pointers for user-supplied heap functions */
+static const void *pContext;
+static UMemAllocFn *pAlloc;
+static UMemReallocFn *pRealloc;
+static UMemFreeFn *pFree;
+
+/* Flag indicating whether any heap allocations have happened.
+ * Used to prevent changing out the heap functions after allocations have been made */
+static UBool gHeapInUse;
+
+U_CAPI void * U_EXPORT2
+uprv_malloc(size_t s) {
+ if (s > 0) {
+ gHeapInUse = TRUE;
+ if (pAlloc) {
+ return (*pAlloc)(pContext, s);
+ } else {
+ return malloc(s);
+ }
+ } else {
+ return (void *)zeroMem;
+ }
+}
+
+U_CAPI void * U_EXPORT2
+uprv_realloc(void * buffer, size_t size) {
+ if (buffer == zeroMem) {
+ return uprv_malloc(size);
+ } else if (size == 0) {
+ if (pFree) {
+ (*pFree)(pContext, buffer);
+ } else {
+ free(buffer);
+ }
+ return (void *)zeroMem;
+ } else {
+ gHeapInUse = TRUE;
+ if (pRealloc) {
+ return (*pRealloc)(pContext, buffer, size);
+ } else {
+ return realloc(buffer, size);
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+uprv_free(void *buffer) {
+ if (buffer != zeroMem) {
+ if (pFree) {
+ (*pFree)(pContext, buffer);
+ } else {
+ free(buffer);
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return;
+ }
+ if (a==NULL || r==NULL || f==NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (gHeapInUse) {
+ *status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ pContext = context;
+ pAlloc = a;
+ pRealloc = r;
+ pFree = f;
+}
+
+
+U_CFUNC UBool cmemory_cleanup(void) {
+ pContext = NULL;
+ pAlloc = NULL;
+ pRealloc = NULL;
+ pFree = NULL;
+ gHeapInUse = FALSE;
+ return TRUE;
+}
+
+
+/*
+ * gHeapInUse
+ * Return True if ICU has allocated any memory.
+ * Used by u_SetMutexFunctions() and similar to verify that ICU has not
+ * been used, that it is in a pristine initial state.
+ */
+U_CFUNC UBool cmemory_inUse() {
+ return gHeapInUse;
+}
+
diff --git a/Build/source/libs/icu/icu-xetex/common/cmemory.h b/Build/source/libs/icu/icu-xetex/common/cmemory.h
new file mode 100644
index 00000000000..da65d7cebf4
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cmemory.h
@@ -0,0 +1,82 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File CMEMORY.H
+*
+* Contains stdlib.h/string.h memory functions
+*
+* @author Bertrand A. Damiba
+*
+* Modification History:
+*
+* Date Name Description
+* 6/20/98 Bertrand Created.
+* 05/03/99 stephen Changed from functions to macros.
+*
+******************************************************************************
+*/
+
+#ifndef CMEMORY_H
+#define CMEMORY_H
+
+#include "unicode/utypes.h"
+#include
+
+
+#define uprv_memcpy(dst, src, size) U_STANDARD_CPP_NAMESPACE memcpy(dst, src, size)
+#define uprv_memmove(dst, src, size) U_STANDARD_CPP_NAMESPACE memmove(dst, src, size)
+#define uprv_memset(buffer, mark, size) U_STANDARD_CPP_NAMESPACE memset(buffer, mark, size)
+#define uprv_memcmp(buffer1, buffer2, size) U_STANDARD_CPP_NAMESPACE memcmp(buffer1, buffer2,size)
+
+U_CAPI void * U_EXPORT2
+uprv_malloc(size_t s);
+
+U_CAPI void * U_EXPORT2
+uprv_realloc(void *mem, size_t size);
+
+U_CAPI void U_EXPORT2
+uprv_free(void *mem);
+
+/**
+ * This should align the memory properly on any machine.
+ * This is very useful for the safeClone functions.
+ */
+typedef union {
+ long t1;
+ double t2;
+ void *t3;
+} UAlignedMemory;
+
+/**
+ * Get the amount of bytes that a pointer is off by from
+ * the previous aligned pointer
+ */
+#define U_ALIGNMENT_OFFSET(ptr) (((size_t)ptr) & (sizeof(UAlignedMemory) - 1))
+
+/**
+ * Get the amount of bytes to add to a pointer
+ * in order to get the next aligned address
+ */
+#define U_ALIGNMENT_OFFSET_UP(ptr) (sizeof(UAlignedMemory) - U_ALIGNMENT_OFFSET(ptr))
+
+/**
+ * Indicate whether the ICU allocation functions have been used.
+ * This is used to determine whether ICU is in an initial, unused state.
+ */
+U_CFUNC UBool
+cmemory_inUse(void);
+
+/**
+ * Heap clean up function, called from u_cleanup()
+ * Clears any user heap functions from u_setMemoryFunctions()
+ * Does NOT deallocate any remaining allocated memory.
+ */
+U_CFUNC UBool
+cmemory_cleanup(void);
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/common.rc b/Build/source/libs/icu/icu-xetex/common/common.rc
new file mode 100644
index 00000000000..331e5423dcc
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/common.rc
@@ -0,0 +1,108 @@
+// Do not edit with Microsoft Developer Studio Resource Editor.
+// It will permanently substitute version numbers that are intended to be
+// picked up by the pre-processor during each build.
+// Copyright (c) 2001-2005 International Business Machines
+// Corporation and others. All Rights Reserved.
+//
+#include "msvcres.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+//
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+#pragma code_page(1252)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "msvcres.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include \0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+#define STR(s) #s
+#define CommaVersionString(a, b, c, d) STR(a) ", " STR(b) ", " STR(c) ", " STR(d) "\0"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, 0
+ PRODUCTVERSION U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, 0
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "00000000"
+ BEGIN
+ VALUE "Comments", ICU_WEBSITE "\0"
+ VALUE "CompanyName", "IBM Corporation and others\0"
+ VALUE "FileDescription", "IBM ICU Common DLL\0"
+ VALUE "FileVersion", CommaVersionString(U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, 0)
+ VALUE "LegalCopyright", U_COPYRIGHT_STRING "\0"
+#ifdef _DEBUG
+ VALUE "OriginalFilename", "icuuc" U_ICU_VERSION_SHORT "d.dll\0")
+#else
+ VALUE "OriginalFilename", "icuuc" U_ICU_VERSION_SHORT ".dll\0")
+#endif
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", "International Components for Unicode\0"
+ VALUE "ProductVersion", CommaVersionString(U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, 0)
+ VALUE "SpecialBuild", "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x000, 0000
+ END
+END
+
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/Build/source/libs/icu/icu-xetex/common/common.vcproj b/Build/source/libs/icu/icu-xetex/common/common.vcproj
new file mode 100644
index 00000000000..d8d6510e581
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/common.vcproj
@@ -0,0 +1,2588 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/cpputils.h b/Build/source/libs/icu/icu-xetex/common/cpputils.h
new file mode 100644
index 00000000000..c1b439c7ff8
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cpputils.h
@@ -0,0 +1,84 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: cpputils.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*/
+
+#ifndef CPPUTILS_H
+#define CPPUTILS_H
+
+#include "unicode/utypes.h"
+#include "unicode/unistr.h"
+#include "cmemory.h"
+
+/*==========================================================================*/
+/* Array copy utility functions */
+/*==========================================================================*/
+
+static
+inline void uprv_arrayCopy(const double* src, double* dst, int32_t count)
+{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const double* src, int32_t srcStart,
+ double* dst, int32_t dstStart, int32_t count)
+{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int8_t* src, int8_t* dst, int32_t count)
+ { uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int8_t* src, int32_t srcStart,
+ int8_t* dst, int32_t dstStart, int32_t count)
+{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int16_t* src, int16_t* dst, int32_t count)
+{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int16_t* src, int32_t srcStart,
+ int16_t* dst, int32_t dstStart, int32_t count)
+{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int32_t* src, int32_t* dst, int32_t count)
+{ uprv_memcpy(dst, src, (size_t)(count * sizeof(*src))); }
+
+static
+inline void uprv_arrayCopy(const int32_t* src, int32_t srcStart,
+ int32_t* dst, int32_t dstStart, int32_t count)
+{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
+
+static
+inline void
+uprv_arrayCopy(const UChar *src, int32_t srcStart,
+ UChar *dst, int32_t dstStart, int32_t count)
+{ uprv_memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
+
+/**
+ * Copy an array of UnicodeString OBJECTS (not pointers).
+ * @internal
+ */
+static inline void
+uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
+{ while(count-- > 0) *dst++ = *src++; }
+
+/**
+ * Copy an array of UnicodeString OBJECTS (not pointers).
+ * @internal
+ */
+static inline void
+uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
+ U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
+{ uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
+
+#endif /* _CPPUTILS */
diff --git a/Build/source/libs/icu/icu-xetex/common/cstring.c b/Build/source/libs/icu/icu-xetex/common/cstring.c
new file mode 100644
index 00000000000..a5b2c6bbccd
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cstring.c
@@ -0,0 +1,328 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File CSTRING.C
+*
+* @author Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+* 6/18/98 hshih Created
+* 09/08/98 stephen Added include for ctype, for Mac Port
+* 11/15/99 helena Integrated S/390 IEEE changes.
+******************************************************************************
+*/
+
+
+
+#include
+#include
+#include "unicode/utypes.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+
+/*
+ * We hardcode case conversion for invariant characters to match our expectation
+ * and the compiler execution charset.
+ * This prevents problems on systems
+ * - with non-default casing behavior, like Turkish system locales where
+ * tolower('I') maps to dotless i and toupper('i') maps to dotted I
+ * - where there are no lowercase Latin characters at all, or using different
+ * codes (some old EBCDIC codepages)
+ *
+ * This works because the compiler usually runs on a platform where the execution
+ * charset includes all of the invariant characters at their expected
+ * code positions, so that the char * string literals in ICU code match
+ * the char literals here.
+ *
+ * Note that the set of lowercase Latin letters is discontiguous in EBCDIC
+ * and the set of uppercase Latin letters is discontiguous as well.
+ */
+
+U_CAPI char U_EXPORT2
+uprv_toupper(char c) {
+#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+ if(('a'<=c && c<='i') || ('j'<=c && c<='r') || ('s'<=c && c<='z')) {
+ c=(char)(c+('A'-'a'));
+ }
+#else
+ if('a'<=c && c<='z') {
+ c=(char)(c+('A'-'a'));
+ }
+#endif
+ return c;
+}
+
+
+#if 0
+/*
+ * Commented out because cstring.h defines uprv_tolower() to be
+ * the same as either uprv_asciitolower() or uprv_ebcdictolower()
+ * to reduce the amount of code to cover with tests.
+ *
+ * Note that this uprv_tolower() definition is likely to work for most
+ * charset families, not just ASCII and EBCDIC, because its #else branch
+ * is written generically.
+ */
+U_CAPI char U_EXPORT2
+uprv_tolower(char c) {
+#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+ if(('A'<=c && c<='I') || ('J'<=c && c<='R') || ('S'<=c && c<='Z')) {
+ c=(char)(c+('a'-'A'));
+ }
+#else
+ if('A'<=c && c<='Z') {
+ c=(char)(c+('a'-'A'));
+ }
+#endif
+ return c;
+}
+#endif
+
+U_CAPI char U_EXPORT2
+uprv_asciitolower(char c) {
+ if(0x41<=c && c<=0x5a) {
+ c=(char)(c+0x20);
+ }
+ return c;
+}
+
+U_CAPI char U_EXPORT2
+uprv_ebcdictolower(char c) {
+ if( (0xc1<=(uint8_t)c && (uint8_t)c<=0xc9) ||
+ (0xd1<=(uint8_t)c && (uint8_t)c<=0xd9) ||
+ (0xe2<=(uint8_t)c && (uint8_t)c<=0xe9)
+ ) {
+ c=(char)(c-0x40);
+ }
+ return c;
+}
+
+
+U_CAPI char* U_EXPORT2
+T_CString_toLowerCase(char* str)
+{
+ char* origPtr = str;
+
+ if (str) {
+ do
+ *str = (char)uprv_tolower(*str);
+ while (*(str++));
+ }
+
+ return origPtr;
+}
+
+U_CAPI char* U_EXPORT2
+T_CString_toUpperCase(char* str)
+{
+ char* origPtr = str;
+
+ if (str) {
+ do
+ *str = (char)uprv_toupper(*str);
+ while (*(str++));
+ }
+
+ return origPtr;
+}
+
+/*
+ * Takes a int32_t and fills in a char* string with that number "radix"-based.
+ * Does not handle negative values (makes an empty string for them).
+ * Writes at most 12 chars ("-2147483647" plus NUL).
+ * Returns the length of the string (not including the NUL).
+ */
+U_CAPI int32_t U_EXPORT2
+T_CString_integerToString(char* buffer, int32_t v, int32_t radix)
+{
+ char tbuf[30];
+ int32_t tbx = sizeof(tbuf);
+ uint8_t digit;
+ int32_t length = 0;
+ uint32_t uval;
+
+ U_ASSERT(radix>=2 && radix<=16);
+ uval = (uint32_t) v;
+ if(v<0 && radix == 10) {
+ /* Only in base 10 do we conside numbers to be signed. */
+ uval = (uint32_t)(-v);
+ buffer[length++] = '-';
+ }
+
+ tbx = sizeof(tbuf)-1;
+ tbuf[tbx] = 0; /* We are generating the digits backwards. Null term the end. */
+ do {
+ digit = (uint8_t)(uval % radix);
+ tbuf[--tbx] = (char)(T_CString_itosOffset(digit));
+ uval = uval / radix;
+ } while (uval != 0);
+
+ /* copy converted number into user buffer */
+ uprv_strcpy(buffer+length, tbuf+tbx);
+ length += sizeof(tbuf) - tbx -1;
+ return length;
+}
+
+
+
+/*
+ * Takes a int64_t and fills in a char* string with that number "radix"-based.
+ * Writes at most 21: chars ("-9223372036854775807" plus NUL).
+ * Returns the length of the string, not including the terminating NULL.
+ */
+U_CAPI int32_t U_EXPORT2
+T_CString_int64ToString(char* buffer, int64_t v, uint32_t radix)
+{
+ char tbuf[30];
+ int32_t tbx = sizeof(tbuf);
+ uint8_t digit;
+ int32_t length = 0;
+ uint64_t uval;
+
+ U_ASSERT(radix>=2 && radix<=16);
+ uval = (uint64_t) v;
+ if(v<0 && radix == 10) {
+ /* Only in base 10 do we conside numbers to be signed. */
+ uval = (uint64_t)(-v);
+ buffer[length++] = '-';
+ }
+
+ tbx = sizeof(tbuf)-1;
+ tbuf[tbx] = 0; /* We are generating the digits backwards. Null term the end. */
+ do {
+ digit = (uint8_t)(uval % radix);
+ tbuf[--tbx] = (char)(T_CString_itosOffset(digit));
+ uval = uval / radix;
+ } while (uval != 0);
+
+ /* copy converted number into user buffer */
+ uprv_strcpy(buffer+length, tbuf+tbx);
+ length += sizeof(tbuf) - tbx -1;
+ return length;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+T_CString_stringToInteger(const char *integerString, int32_t radix)
+{
+ char *end;
+ return uprv_strtoul(integerString, &end, radix);
+
+}
+
+U_CAPI int U_EXPORT2
+T_CString_stricmp(const char *str1, const char *str2) {
+ if(str1==NULL) {
+ if(str2==NULL) {
+ return 0;
+ } else {
+ return -1;
+ }
+ } else if(str2==NULL) {
+ return 1;
+ } else {
+ /* compare non-NULL strings lexically with lowercase */
+ int rc;
+ unsigned char c1, c2;
+
+ for(;;) {
+ c1=(unsigned char)*str1;
+ c2=(unsigned char)*str2;
+ if(c1==0) {
+ if(c2==0) {
+ return 0;
+ } else {
+ return -1;
+ }
+ } else if(c2==0) {
+ return 1;
+ } else {
+ /* compare non-zero characters with lowercase */
+ rc=(int)(unsigned char)uprv_tolower(c1)-(int)(unsigned char)uprv_tolower(c2);
+ if(rc!=0) {
+ return rc;
+ }
+ }
+ ++str1;
+ ++str2;
+ }
+ }
+}
+
+U_CAPI int U_EXPORT2
+T_CString_strnicmp(const char *str1, const char *str2, uint32_t n) {
+ if(str1==NULL) {
+ if(str2==NULL) {
+ return 0;
+ } else {
+ return -1;
+ }
+ } else if(str2==NULL) {
+ return 1;
+ } else {
+ /* compare non-NULL strings lexically with lowercase */
+ int rc;
+ unsigned char c1, c2;
+
+ for(; n--;) {
+ c1=(unsigned char)*str1;
+ c2=(unsigned char)*str2;
+ if(c1==0) {
+ if(c2==0) {
+ return 0;
+ } else {
+ return -1;
+ }
+ } else if(c2==0) {
+ return 1;
+ } else {
+ /* compare non-zero characters with lowercase */
+ rc=(int)(unsigned char)uprv_tolower(c1)-(int)(unsigned char)uprv_tolower(c2);
+ if(rc!=0) {
+ return rc;
+ }
+ }
+ ++str1;
+ ++str2;
+ }
+ }
+
+ return 0;
+}
+
+U_CAPI char* U_EXPORT2
+uprv_strdup(const char *src) {
+ size_t len = uprv_strlen(src) + 1;
+ char *dup = (char *) uprv_malloc(len);
+
+ if (dup) {
+ uprv_memcpy(dup, src, len);
+ }
+
+ return dup;
+}
+
+U_CAPI char* U_EXPORT2
+uprv_strndup(const char *src, int32_t n) {
+ char *dup;
+
+ if(n < 0) {
+ dup = uprv_strdup(src);
+ } else {
+ dup = (char*)uprv_malloc(n+1);
+ if (dup) {
+ uprv_memcpy(dup, src, n);
+ dup[n] = 0;
+ }
+ }
+
+ return dup;
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/cstring.h b/Build/source/libs/icu/icu-xetex/common/cstring.h
new file mode 100644
index 00000000000..6d2fd0e8159
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cstring.h
@@ -0,0 +1,120 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File CSTRING.H
+*
+* Contains CString interface
+*
+* @author Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+* 6/17/98 hshih Created.
+* 05/03/99 stephen Changed from functions to macros.
+* 06/14/99 stephen Added icu_strncat, icu_strncmp, icu_tolower
+*
+******************************************************************************
+*/
+
+#ifndef CSTRING_H
+#define CSTRING_H 1
+
+#include "unicode/utypes.h"
+#include
+#include
+#include
+
+#define uprv_strcpy(dst, src) U_STANDARD_CPP_NAMESPACE strcpy(dst, src)
+#define uprv_strncpy(dst, src, size) U_STANDARD_CPP_NAMESPACE strncpy(dst, src, size)
+#define uprv_strlen(str) U_STANDARD_CPP_NAMESPACE strlen(str)
+#define uprv_strcmp(s1, s2) U_STANDARD_CPP_NAMESPACE strcmp(s1, s2)
+#define uprv_strncmp(s1, s2, n) U_STANDARD_CPP_NAMESPACE strncmp(s1, s2, n)
+#define uprv_strcat(dst, src) U_STANDARD_CPP_NAMESPACE strcat(dst, src)
+#define uprv_strncat(dst, src, n) U_STANDARD_CPP_NAMESPACE strncat(dst, src, n)
+#define uprv_strchr(s, c) U_STANDARD_CPP_NAMESPACE strchr(s, c)
+#define uprv_strstr(s, c) U_STANDARD_CPP_NAMESPACE strstr(s, c)
+#define uprv_strrchr(s, c) U_STANDARD_CPP_NAMESPACE strrchr(s, c)
+
+U_CAPI char U_EXPORT2
+uprv_toupper(char c);
+
+
+U_CAPI char U_EXPORT2
+uprv_asciitolower(char c);
+
+U_CAPI char U_EXPORT2
+uprv_ebcdictolower(char c);
+
+#if U_CHARSET_FAMILY==U_ASCII_FAMILY
+# define uprv_tolower uprv_asciitolower
+#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+# define uprv_tolower uprv_ebcdictolower
+#else
+# error U_CHARSET_FAMILY is not valid
+#endif
+
+#define uprv_strtod(source, end) U_STANDARD_CPP_NAMESPACE strtod(source, end)
+#define uprv_strtoul(str, end, base) U_STANDARD_CPP_NAMESPACE strtoul(str, end, base)
+#define uprv_strtol(str, end, base) U_STANDARD_CPP_NAMESPACE strtol(str, end, base)
+#ifdef U_WINDOWS
+# if defined(__BORLANDC__)
+# define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE stricmp(str1, str2)
+# define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE strnicmp(str1, str2, n)
+# else
+# define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE _stricmp(str1, str2)
+# define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE _strnicmp(str1, str2, n)
+# endif
+#elif defined(POSIX)
+# define uprv_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE strcasecmp(str1, str2)
+# define uprv_strnicmp(str1, str2, n) U_STANDARD_CPP_NAMESPACE strncasecmp(str1, str2, n)
+#else
+# define uprv_stricmp(str1, str2) T_CString_stricmp(str1, str2)
+# define uprv_strnicmp(str1, str2, n) T_CString_strnicmp(str1, str2, n)
+#endif
+
+/* Conversion from a digit to the character with radix base from 2-19 */
+/* May need to use U_UPPER_ORDINAL*/
+#define T_CString_itosOffset(a) ((a)<=9?('0'+(a)):('A'+(a)-10))
+
+U_CAPI char* U_EXPORT2
+uprv_strdup(const char *src);
+
+/**
+ * uprv_malloc n+1 bytes, and copy n bytes from src into the new string.
+ * Terminate with a null at offset n. If n is -1, works like uprv_strdup
+ * @param src
+ * @param n length of the input string, not including null.
+ * @return new string (owned by caller, use uprv_free to free).
+ * @internal
+ */
+U_CAPI char* U_EXPORT2
+uprv_strndup(const char *src, int32_t n);
+
+U_CAPI char* U_EXPORT2
+T_CString_toLowerCase(char* str);
+
+U_CAPI char* U_EXPORT2
+T_CString_toUpperCase(char* str);
+
+U_CAPI int32_t U_EXPORT2
+T_CString_integerToString(char *buffer, int32_t n, int32_t radix);
+
+U_CAPI int32_t U_EXPORT2
+T_CString_int64ToString(char *buffer, int64_t n, uint32_t radix);
+
+U_CAPI int32_t U_EXPORT2
+T_CString_stringToInteger(const char *integerString, int32_t radix);
+
+U_CAPI int U_EXPORT2
+T_CString_stricmp(const char *str1, const char *str2);
+
+U_CAPI int U_EXPORT2
+T_CString_strnicmp(const char *str1, const char *str2, uint32_t n);
+
+#endif /* ! CSTRING_H */
diff --git a/Build/source/libs/icu/icu-xetex/common/cwchar.c b/Build/source/libs/icu/icu-xetex/common/cwchar.c
new file mode 100644
index 00000000000..78bb8c59dbb
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cwchar.c
@@ -0,0 +1,53 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2001, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: cwchar.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001may25
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !U_HAVE_WCSCPY
+
+#include "cwchar.h"
+
+U_CAPI wchar_t *uprv_wcscat(wchar_t *dst, const wchar_t *src) {
+ wchar_t *start=dst;
+ while(*dst!=0) {
+ ++dst;
+ }
+ while((*dst=*src)!=0) {
+ ++dst;
+ ++src;
+ }
+ return start;
+}
+
+U_CAPI wchar_t *uprv_wcscpy(wchar_t *dst, const wchar_t *src) {
+ wchar_t *start=dst;
+ while((*dst=*src)!=0) {
+ ++dst;
+ ++src;
+ }
+ return start;
+}
+
+U_CAPI size_t uprv_wcslen(const wchar_t *src) {
+ const wchar_t *start=src;
+ while(*src!=0) {
+ ++src;
+ }
+ return src-start;
+}
+
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/cwchar.h b/Build/source/libs/icu/icu-xetex/common/cwchar.h
new file mode 100644
index 00000000000..2ab36c032e0
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/cwchar.h
@@ -0,0 +1,56 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2001, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: cwchar.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001may25
+* created by: Markus W. Scherer
+*
+* This file contains ICU-internal definitions of wchar_t operations.
+* These definitions were moved here from cstring.h so that fewer
+* ICU implementation files include wchar.h.
+*/
+
+#ifndef __CWCHAR_H__
+#define __CWCHAR_H__
+
+#include
+#include
+#include "unicode/utypes.h"
+
+/* Do this after utypes.h so that we have U_HAVE_WCHAR_H . */
+#if U_HAVE_WCHAR_H
+# include
+#endif
+
+/*===========================================================================*/
+/* Wide-character functions */
+/*===========================================================================*/
+
+/* The following are not available on all systems, defined in wchar.h or string.h. */
+#if U_HAVE_WCSCPY
+# define uprv_wcscpy wcscpy
+# define uprv_wcscat wcscat
+# define uprv_wcslen wcslen
+#else
+U_CAPI wchar_t* U_EXPORT2
+uprv_wcscpy(wchar_t *dst, const wchar_t *src);
+U_CAPI wchar_t* U_EXPORT2
+uprv_wcscat(wchar_t *dst, const wchar_t *src);
+U_CAPI size_t U_EXPORT2
+uprv_wcslen(const wchar_t *src);
+#endif
+
+/* The following are part of the ANSI C standard, defined in stdlib.h . */
+#define uprv_wcstombs(mbstr, wcstr, count) U_STANDARD_CPP_NAMESPACE wcstombs(mbstr, wcstr, count)
+#define uprv_mbstowcs(wcstr, mbstr, count) U_STANDARD_CPP_NAMESPACE mbstowcs(wcstr, mbstr, count)
+
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/dictbe.cpp b/Build/source/libs/icu/icu-xetex/common/dictbe.cpp
new file mode 100644
index 00000000000..a779727ff47
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/dictbe.cpp
@@ -0,0 +1,426 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2006, International Business Machines Corporation and others. *
+ * All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "brkeng.h"
+#include "dictbe.h"
+#include "unicode/uniset.h"
+#include "unicode/chariter.h"
+#include "unicode/ubrk.h"
+#include "uvector.h"
+#include "triedict.h"
+
+U_NAMESPACE_BEGIN
+
+/*
+ ******************************************************************
+ */
+
+/*DictionaryBreakEngine::DictionaryBreakEngine() {
+ fTypes = 0;
+}*/
+
+DictionaryBreakEngine::DictionaryBreakEngine(uint32_t breakTypes) {
+ fTypes = breakTypes;
+}
+
+DictionaryBreakEngine::~DictionaryBreakEngine() {
+}
+
+UBool
+DictionaryBreakEngine::handles(UChar32 c, int32_t breakType) const {
+ return (breakType >= 0 && breakType < 32 && (((uint32_t)1 << breakType) & fTypes)
+ && fSet.contains(c));
+}
+
+int32_t
+DictionaryBreakEngine::findBreaks( UText *text,
+ int32_t startPos,
+ int32_t endPos,
+ UBool reverse,
+ int32_t breakType,
+ UStack &foundBreaks ) const {
+ int32_t result = 0;
+
+ // Find the span of characters included in the set.
+ int32_t start = (int32_t)utext_getNativeIndex(text);
+ int32_t current;
+ int32_t rangeStart;
+ int32_t rangeEnd;
+ UChar32 c = utext_current32(text);
+ if (reverse) {
+ UBool isDict = fSet.contains(c);
+ while((current = (int32_t)utext_getNativeIndex(text)) > startPos && isDict) {
+ c = utext_previous32(text);
+ isDict = fSet.contains(c);
+ }
+ rangeStart = (current < startPos) ? startPos : current+(isDict ? 0 : 1);
+ rangeEnd = start + 1;
+ }
+ else {
+ while((current = (int32_t)utext_getNativeIndex(text)) < endPos && fSet.contains(c)) {
+ utext_next32(text); // TODO: recast loop for postincrement
+ c = utext_current32(text);
+ }
+ rangeStart = start;
+ rangeEnd = current;
+ }
+ if (breakType >= 0 && breakType < 32 && (((uint32_t)1 << breakType) & fTypes)) {
+ result = divideUpDictionaryRange(text, rangeStart, rangeEnd, foundBreaks);
+ utext_setNativeIndex(text, current);
+ }
+
+ return result;
+}
+
+void
+DictionaryBreakEngine::setCharacters( const UnicodeSet &set ) {
+ fSet = set;
+ // Compact for caching
+ fSet.compact();
+}
+
+/*void
+DictionaryBreakEngine::setBreakTypes( uint32_t breakTypes ) {
+ fTypes = breakTypes;
+}*/
+
+/*
+ ******************************************************************
+ */
+
+
+// Helper class for improving readability of the Thai word break
+// algorithm. The implementation is completely inline.
+
+// List size, limited by the maximum number of words in the dictionary
+// that form a nested sequence.
+#define POSSIBLE_WORD_LIST_MAX 20
+
+class PossibleWord {
+ private:
+ // list of word candidate lengths, in increasing length order
+ int32_t lengths[POSSIBLE_WORD_LIST_MAX];
+ int count; // Count of candidates
+ int32_t prefix; // The longest match with a dictionary word
+ int32_t offset; // Offset in the text of these candidates
+ int mark; // The preferred candidate's offset
+ int current; // The candidate we're currently looking at
+
+ public:
+ PossibleWord();
+ ~PossibleWord();
+
+ // Fill the list of candidates if needed, select the longest, and return the number found
+ int candidates( UText *text, const TrieWordDictionary *dict, int32_t rangeEnd );
+
+ // Select the currently marked candidate, point after it in the text, and invalidate self
+ int32_t acceptMarked( UText *text );
+
+ // Back up from the current candidate to the next shorter one; return TRUE if that exists
+ // and point the text after it
+ UBool backUp( UText *text );
+
+ // Return the longest prefix this candidate location shares with a dictionary word
+ int32_t longestPrefix();
+
+ // Mark the current candidate as the one we like
+ void markCurrent();
+};
+
+inline
+PossibleWord::PossibleWord() {
+ offset = -1;
+}
+
+inline
+PossibleWord::~PossibleWord() {
+}
+
+inline int
+PossibleWord::candidates( UText *text, const TrieWordDictionary *dict, int32_t rangeEnd ) {
+ // TODO: If getIndex is too slow, use offset < 0 and add discardAll()
+ int32_t start = (int32_t)utext_getNativeIndex(text);
+ if (start != offset) {
+ offset = start;
+ prefix = dict->matches(text, rangeEnd-start, lengths, count, sizeof(lengths)/sizeof(lengths[0]));
+ // Dictionary leaves text after longest prefix, not longest word. Back up.
+ if (count <= 0) {
+ utext_setNativeIndex(text, start);
+ }
+ }
+ if (count > 0) {
+ utext_setNativeIndex(text, start+lengths[count-1]);
+ }
+ current = count-1;
+ mark = current;
+ return count;
+}
+
+inline int32_t
+PossibleWord::acceptMarked( UText *text ) {
+ utext_setNativeIndex(text, offset + lengths[mark]);
+ return lengths[mark];
+}
+
+inline UBool
+PossibleWord::backUp( UText *text ) {
+ if (current > 0) {
+ utext_setNativeIndex(text, offset + lengths[--current]);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+inline int32_t
+PossibleWord::longestPrefix() {
+ return prefix;
+}
+
+inline void
+PossibleWord::markCurrent() {
+ mark = current;
+}
+
+// How many words in a row are "good enough"?
+#define THAI_LOOKAHEAD 3
+
+// Will not combine a non-word with a preceding dictionary word longer than this
+#define THAI_ROOT_COMBINE_THRESHOLD 3
+
+// Will not combine a non-word that shares at least this much prefix with a
+// dictionary word, with a preceding word
+#define THAI_PREFIX_COMBINE_THRESHOLD 3
+
+// Ellision character
+#define THAI_PAIYANNOI 0x0E2F
+
+// Repeat character
+#define THAI_MAIYAMOK 0x0E46
+
+// Minimum word size
+#define THAI_MIN_WORD 2
+
+// Minimum number of characters for two words
+#define THAI_MIN_WORD_SPAN (THAI_MIN_WORD * 2)
+
+ThaiBreakEngine::ThaiBreakEngine(const TrieWordDictionary *adoptDictionary, UErrorCode &status)
+ : DictionaryBreakEngine((1< 1) {
+ // If we're already at the end of the range, we're done
+ if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
+ goto foundBest;
+ }
+ do {
+ int wordsMatched = 1;
+ if (words[(wordsFound+1)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) > 0) {
+ if (wordsMatched < 2) {
+ // Followed by another dictionary word; mark first word as a good candidate
+ words[wordsFound%THAI_LOOKAHEAD].markCurrent();
+ wordsMatched = 2;
+ }
+
+ // If we're already at the end of the range, we're done
+ if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
+ goto foundBest;
+ }
+
+ // See if any of the possible second words is followed by a third word
+ do {
+ // If we find a third word, stop right away
+ if (words[(wordsFound+2)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd)) {
+ words[wordsFound%THAI_LOOKAHEAD].markCurrent();
+ goto foundBest;
+ }
+ }
+ while (words[(wordsFound+1)%THAI_LOOKAHEAD].backUp(text));
+ }
+ }
+ while (words[wordsFound%THAI_LOOKAHEAD].backUp(text));
+foundBest:
+ wordLength = words[wordsFound%THAI_LOOKAHEAD].acceptMarked(text);
+ wordsFound += 1;
+ }
+
+ // We come here after having either found a word or not. We look ahead to the
+ // next word. If it's not a dictionary word, we will combine it withe the word we
+ // just found (if there is one), but only if the preceding word does not exceed
+ // the threshold.
+ // The text iterator should now be positioned at the end of the word we found.
+ if ((int32_t)utext_getNativeIndex(text) < rangeEnd && wordLength < THAI_ROOT_COMBINE_THRESHOLD) {
+ // if it is a dictionary word, do nothing. If it isn't, then if there is
+ // no preceding word, or the non-word shares less than the minimum threshold
+ // of characters with a dictionary word, then scan to resynchronize
+ if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0
+ && (wordLength == 0
+ || words[wordsFound%THAI_LOOKAHEAD].longestPrefix() < THAI_PREFIX_COMBINE_THRESHOLD)) {
+ // Look for a plausible word boundary
+ //TODO: This section will need a rework for UText.
+ int32_t remaining = rangeEnd - (current+wordLength);
+ UChar32 pc = utext_current32(text);
+ int32_t chars = 0;
+ for (;;) {
+ utext_next32(text);
+ uc = utext_current32(text);
+ // TODO: Here we're counting on the fact that the SA languages are all
+ // in the BMP. This should get fixed with the UText rework.
+ chars += 1;
+ if (--remaining <= 0) {
+ break;
+ }
+ if (fEndWordSet.contains(pc) && fBeginWordSet.contains(uc)) {
+ // Maybe. See if it's in the dictionary.
+ // NOTE: In the original Apple code, checked that the next
+ // two characters after uc were not 0x0E4C THANTHAKHAT before
+ // checking the dictionary. That is just a performance filter,
+ // but it's not clear it's faster than checking the trie.
+ int candidates = words[(wordsFound+1)%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd);
+ utext_setNativeIndex(text, current+wordLength+chars);
+ if (candidates > 0) {
+ break;
+ }
+ }
+ pc = uc;
+ }
+
+ // Bump the word count if there wasn't already one
+ if (wordLength <= 0) {
+ wordsFound += 1;
+ }
+
+ // Update the length with the passed-over characters
+ wordLength += chars;
+ }
+ else {
+ // Back up to where we were for next iteration
+ utext_setNativeIndex(text, current+wordLength);
+ }
+ }
+
+ // Never stop before a combining mark.
+ int32_t currPos;
+ while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
+ utext_next32(text);
+ wordLength += (int32_t)utext_getNativeIndex(text) - currPos;
+ }
+
+ // Look ahead for possible suffixes if a dictionary word does not follow.
+ // We do this in code rather than using a rule so that the heuristic
+ // resynch continues to function. For example, one of the suffix characters
+ // could be a typo in the middle of a word.
+ if ((int32_t)utext_getNativeIndex(text) < rangeEnd && wordLength > 0) {
+ if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0
+ && fSuffixSet.contains(uc = utext_current32(text))) {
+ if (uc == THAI_PAIYANNOI) {
+ if (!fSuffixSet.contains(utext_previous32(text))) {
+ // Skip over previous end and PAIYANNOI
+ utext_next32(text);
+ utext_next32(text);
+ wordLength += 1; // Add PAIYANNOI to word
+ uc = utext_current32(text); // Fetch next character
+ }
+ else {
+ // Restore prior position
+ utext_next32(text);
+ }
+ }
+ if (uc == THAI_MAIYAMOK) {
+ if (utext_previous32(text) != THAI_MAIYAMOK) {
+ // Skip over previous end and MAIYAMOK
+ utext_next32(text);
+ utext_next32(text);
+ wordLength += 1; // Add MAIYAMOK to word
+ }
+ else {
+ // Restore prior position
+ utext_next32(text);
+ }
+ }
+ }
+ else {
+ utext_setNativeIndex(text, current+wordLength);
+ }
+ }
+
+ // Did we find a word on this iteration? If so, push it on the break stack
+ if (wordLength > 0) {
+ foundBreaks.push((current+wordLength), status);
+ }
+ }
+
+ // Don't return a break for the end of the dictionary range if there is one there.
+ if (foundBreaks.peeki() >= rangeEnd) {
+ (void) foundBreaks.popi();
+ wordsFound -= 1;
+ }
+
+ return wordsFound;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/dictbe.h b/Build/source/libs/icu/icu-xetex/common/dictbe.h
new file mode 100644
index 00000000000..d6f8b1462d2
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/dictbe.h
@@ -0,0 +1,193 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2006, International Business Machines Corporation and others. *
+ * All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef DICTBE_H
+#define DICTBE_H
+
+#include "unicode/utypes.h"
+#include "unicode/uniset.h"
+#include "unicode/utext.h"
+
+#include "brkeng.h"
+
+U_NAMESPACE_BEGIN
+
+class TrieWordDictionary;
+
+/*******************************************************************
+ * DictionaryBreakEngine
+ */
+
+/**
+ * DictionaryBreakEngine is a kind of LanguageBreakEngine that uses a
+ * dictionary to determine language-specific breaks.
+ *
+ * After it is constructed a DictionaryBreakEngine may be shared between
+ * threads without synchronization.
+ */
+class DictionaryBreakEngine : public LanguageBreakEngine {
+ private:
+ /**
+ * The set of characters handled by this engine
+ * @internal
+ */
+
+ UnicodeSet fSet;
+
+ /**
+ * The set of break types handled by this engine
+ * @internal
+ */
+
+ uint32_t fTypes;
+
+ /**
+ * Default constructor.
+ *
+ */
+ DictionaryBreakEngine();
+
+ public:
+
+ /**
+ * Constructor setting the break types handled.
+ *
+ * @param breakTypes A bitmap of types handled by the engine.
+ */
+ DictionaryBreakEngine( uint32_t breakTypes );
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~DictionaryBreakEngine();
+
+ /**
+ * Indicate whether this engine handles a particular character for
+ * a particular kind of break.
+ *
+ * @param c A character which begins a run that the engine might handle
+ * @param breakType The type of text break which the caller wants to determine
+ * @return TRUE if this engine handles the particular character and break
+ * type.
+ */
+ virtual UBool handles( UChar32 c, int32_t breakType ) const;
+
+ /**
+ * Find any breaks within a run in the supplied text.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left at the end of the run of characters which the engine
+ * is capable of handling.
+ * @param startPos The start of the run within the supplied text.
+ * @param endPos The end of the run within the supplied text.
+ * @param reverse Whether the caller is looking for breaks in a reverse
+ * direction.
+ * @param breakType The type of break desired, or -1.
+ * @param foundBreaks An allocated C array of the breaks found, if any
+ * @return The number of breaks found.
+ */
+ virtual int32_t findBreaks( UText *text,
+ int32_t startPos,
+ int32_t endPos,
+ UBool reverse,
+ int32_t breakType,
+ UStack &foundBreaks ) const;
+
+ protected:
+
+ /**
+ * Set the character set handled by this engine.
+ *
+ * @param set A UnicodeSet of the set of characters handled by the engine
+ */
+ virtual void setCharacters( const UnicodeSet &set );
+
+ /**
+ * Set the break types handled by this engine.
+ *
+ * @param breakTypes A bitmap of types handled by the engine.
+ */
+// virtual void setBreakTypes( uint32_t breakTypes );
+
+ /**
+ * Divide up a range of known dictionary characters.
+ *
+ * @param text A UText representing the text
+ * @param rangeStart The start of the range of dictionary characters
+ * @param rangeEnd The end of the range of dictionary characters
+ * @param foundBreaks Output of C array of int32_t break positions, or 0
+ * @return The number of breaks found
+ */
+ virtual int32_t divideUpDictionaryRange( UText *text,
+ int32_t rangeStart,
+ int32_t rangeEnd,
+ UStack &foundBreaks ) const = 0;
+
+};
+
+/*******************************************************************
+ * ThaiBreakEngine
+ */
+
+/**
+ * ThaiBreakEngine is a kind of DictionaryBreakEngine that uses a
+ * TrieWordDictionary and heuristics to determine Thai-specific breaks.
+ *
+ * After it is constructed a ThaiBreakEngine may be shared between
+ * threads without synchronization.
+ */
+class ThaiBreakEngine : public DictionaryBreakEngine {
+ private:
+ /**
+ * The set of characters handled by this engine
+ * @internal
+ */
+
+ UnicodeSet fThaiWordSet;
+ UnicodeSet fEndWordSet;
+ UnicodeSet fBeginWordSet;
+ UnicodeSet fSuffixSet;
+ UnicodeSet fMarkSet;
+ const TrieWordDictionary *fDictionary;
+
+ public:
+
+ /**
+ * Default constructor.
+ *
+ * @param adoptDictionary A TrieWordDictionary to adopt. Deleted when the
+ * engine is deleted.
+ */
+ ThaiBreakEngine(const TrieWordDictionary *adoptDictionary, UErrorCode &status);
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~ThaiBreakEngine();
+
+ protected:
+ /**
+ * Divide up a range of known dictionary characters.
+ *
+ * @param text A UText representing the text
+ * @param rangeStart The start of the range of dictionary characters
+ * @param rangeEnd The end of the range of dictionary characters
+ * @param foundBreaks Output of C array of int32_t break positions, or 0
+ * @return The number of breaks found
+ */
+ virtual int32_t divideUpDictionaryRange( UText *text,
+ int32_t rangeStart,
+ int32_t rangeEnd,
+ UStack &foundBreaks ) const;
+
+};
+
+
+U_NAMESPACE_END
+
+ /* DICTBE_H */
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/hash.h b/Build/source/libs/icu/icu-xetex/common/hash.h
new file mode 100644
index 00000000000..375499bf1b8
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/hash.h
@@ -0,0 +1,207 @@
+/*
+******************************************************************************
+* Copyright (C) 1997-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* Date Name Description
+* 03/28/00 aliu Creation.
+******************************************************************************
+*/
+
+#ifndef HASH_H
+#define HASH_H
+
+#include "unicode/unistr.h"
+#include "unicode/uobject.h"
+#include "uhash.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Hashtable is a thin C++ wrapper around UHashtable, a general-purpose void*
+ * hashtable implemented in C. Hashtable is designed to be idiomatic and
+ * easy-to-use in C++.
+ *
+ * Hashtable is an INTERNAL CLASS.
+ */
+class U_COMMON_API Hashtable : public UMemory {
+ UHashtable* hash;
+ UHashtable hashObj;
+
+ inline void init(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
+
+public:
+ /**
+ * Construct a hashtable
+ * @param ignoreKeyCase If true, keys are case insensitive.
+ * @param status Error code
+ */
+ Hashtable(UBool ignoreKeyCase, UErrorCode& status);
+
+ /**
+ * Construct a hashtable
+ * @param keyComp Compartor for comparing the keys
+ * @param valueComp Compartor for comparing the values
+ * @param status Error code
+ */
+ Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
+
+ /**
+ * Construct a hashtable
+ * @param status Error code
+ */
+ Hashtable(UErrorCode& status);
+
+ /**
+ * Construct a hashtable, _disregarding any error_. Use this constructor
+ * with caution.
+ */
+ Hashtable();
+
+ /**
+ * Non-virtual destructor; make this virtual if Hashtable is subclassed
+ * in the future.
+ */
+ ~Hashtable();
+
+ UObjectDeleter *setValueDeleter(UObjectDeleter *fn);
+
+ int32_t count() const;
+
+ void* put(const UnicodeString& key, void* value, UErrorCode& status);
+
+ int32_t puti(const UnicodeString& key, int32_t value, UErrorCode& status);
+
+ void* get(const UnicodeString& key) const;
+
+ int32_t geti(const UnicodeString& key) const;
+
+ void* remove(const UnicodeString& key);
+
+ int32_t removei(const UnicodeString& key);
+
+ void removeAll(void);
+
+ const UHashElement* find(const UnicodeString& key) const;
+
+ const UHashElement* nextElement(int32_t& pos) const;
+
+ UKeyComparator* setKeyCompartor(UKeyComparator*keyComp);
+
+ UValueComparator* setValueCompartor(UValueComparator* valueComp);
+
+ UBool equals(const Hashtable& that) const;
+private:
+ Hashtable(const Hashtable &other); // forbid copying of this class
+ Hashtable &operator=(const Hashtable &other); // forbid copying of this class
+};
+
+/*********************************************************************
+ * Implementation
+ ********************************************************************/
+
+inline void Hashtable::init(UHashFunction *keyHash, UKeyComparator *keyComp,
+ UValueComparator *valueComp, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ uhash_init(&hashObj, keyHash, keyComp, valueComp, &status);
+ if (U_SUCCESS(status)) {
+ hash = &hashObj;
+ uhash_setKeyDeleter(hash, uhash_deleteUnicodeString);
+ }
+}
+
+inline Hashtable::Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp,
+ UErrorCode& status) : hash(0) {
+ init( uhash_hashUnicodeString, keyComp, valueComp, status);
+}
+inline Hashtable::Hashtable(UBool ignoreKeyCase, UErrorCode& status)
+ : hash(0)
+{
+ init(ignoreKeyCase ? uhash_hashCaselessUnicodeString
+ : uhash_hashUnicodeString,
+ ignoreKeyCase ? uhash_compareCaselessUnicodeString
+ : uhash_compareUnicodeString,
+ NULL,
+ status);
+}
+
+inline Hashtable::Hashtable(UErrorCode& status)
+ : hash(0)
+{
+ init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
+}
+
+inline Hashtable::Hashtable()
+ : hash(0)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
+}
+
+inline Hashtable::~Hashtable() {
+ if (hash != NULL) {
+ uhash_close(hash);
+ }
+}
+
+inline UObjectDeleter *Hashtable::setValueDeleter(UObjectDeleter *fn) {
+ return uhash_setValueDeleter(hash, fn);
+}
+
+inline int32_t Hashtable::count() const {
+ return uhash_count(hash);
+}
+
+inline void* Hashtable::put(const UnicodeString& key, void* value, UErrorCode& status) {
+ return uhash_put(hash, new UnicodeString(key), value, &status);
+}
+
+inline int32_t Hashtable::puti(const UnicodeString& key, int32_t value, UErrorCode& status) {
+ return uhash_puti(hash, new UnicodeString(key), value, &status);
+}
+
+inline void* Hashtable::get(const UnicodeString& key) const {
+ return uhash_get(hash, &key);
+}
+
+inline int32_t Hashtable::geti(const UnicodeString& key) const {
+ return uhash_geti(hash, &key);
+}
+
+inline void* Hashtable::remove(const UnicodeString& key) {
+ return uhash_remove(hash, &key);
+}
+
+inline int32_t Hashtable::removei(const UnicodeString& key) {
+ return uhash_removei(hash, &key);
+}
+
+inline const UHashElement* Hashtable::find(const UnicodeString& key) const {
+ return uhash_find(hash, &key);
+}
+
+inline const UHashElement* Hashtable::nextElement(int32_t& pos) const {
+ return uhash_nextElement(hash, &pos);
+}
+
+inline void Hashtable::removeAll(void) {
+ uhash_removeAll(hash);
+}
+
+inline UKeyComparator* Hashtable::setKeyCompartor(UKeyComparator*keyComp){
+ return uhash_setKeyComparator(hash, keyComp);
+}
+
+inline UValueComparator* Hashtable::setValueCompartor(UValueComparator* valueComp){
+ return uhash_setValueComparator(hash, valueComp);
+}
+
+inline UBool Hashtable::equals(const Hashtable& that)const{
+ return uhash_equals(hash, that.hash);
+}
+U_NAMESPACE_END
+
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/icucfg.h.in b/Build/source/libs/icu/icu-xetex/common/icucfg.h.in
new file mode 100644
index 00000000000..98fc0ff9373
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/icucfg.h.in
@@ -0,0 +1,61 @@
+/* common/icucfg.h.in. Generated automatically from configure.in by autoheader. */
+
+/* Define if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define if your processor stores words with the most significant
+ byte first (like Motorola and SPARC, unlike Intel and VAX). */
+#undef WORDS_BIGENDIAN
+
+/* Copyright (c) 1999-2000, International Business Machines Corporation and
+ others. All Rights Reserved. */
+/* Define to signed char if not in */
+#undef int8_t
+
+/* Define to unsigned char if not in */
+#undef uint8_t
+
+/* Define to signed short if not in */
+#undef int16_t
+
+/* Define to unsigned short if not in */
+#undef uint16_t
+
+/* Define to signed long if not in */
+#undef int32_t
+
+/* Define to unsigned long if not in */
+#undef uint32_t
+
+/* Define to signed char if not in */
+#undef bool_t
+
+/* Define if your system has */
+#undef HAVE_WCHAR_H
+
+/* Define to the size of wchar_t */
+#undef SIZEOF_WCHAR_T
+
+/* Define if you have the header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define if you have the cma library (-lcma). */
+#undef HAVE_LIBCMA
+
+/* Define if you have the dl library (-ldl). */
+#undef HAVE_LIBDL
+
+/* Define if you have the dld library (-ldld). */
+#undef HAVE_LIBDLD
+
+/* Define if you have the m library (-lm). */
+#undef HAVE_LIBM
+
+/* Define if you have the pthread library (-lpthread). */
+#undef HAVE_LIBPTHREAD
+
+/* Define if you have the pthreads library (-lpthreads). */
+#undef HAVE_LIBPTHREADS
+
+/* Define if you have the wcs library (-lwcs). */
+#undef HAVE_LIBWCS
diff --git a/Build/source/libs/icu/icu-xetex/common/localsvc.h b/Build/source/libs/icu/icu-xetex/common/localsvc.h
new file mode 100644
index 00000000000..67e5a8455ae
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/localsvc.h
@@ -0,0 +1,25 @@
+/*
+***************************************************************************
+* Copyright (C) 2006 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+
+#ifndef LOCALSVC_H
+#define LOCALSVC_H
+
+#include "unicode/utypes.h"
+
+#if U_LOCAL_SERVICE_HOOK
+/**
+ * Prototype for user-supplied service hook. This function is expected to return
+ * a type of factory object specific to the requested service.
+ *
+ * @param what service-specific string identifying the specific user hook
+ * @param status error status
+ * @return a service-specific hook, or NULL on failure.
+ */
+U_CAPI void* uprv_svc_hook(const char *what, UErrorCode *status);
+#endif
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/locbased.cpp b/Build/source/libs/icu/icu-xetex/common/locbased.cpp
new file mode 100644
index 00000000000..e96b9f79f3d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locbased.cpp
@@ -0,0 +1,46 @@
+/*
+**********************************************************************
+* Copyright (c) 2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: January 16 2004
+* Since: ICU 2.8
+**********************************************************************
+*/
+#include "locbased.h"
+#include "cstring.h"
+
+U_NAMESPACE_BEGIN
+
+Locale LocaleBased::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ const char* id = getLocaleID(type, status);
+ return Locale((id != 0) ? id : "");
+}
+
+const char* LocaleBased::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ switch(type) {
+ case ULOC_VALID_LOCALE:
+ return valid;
+ case ULOC_ACTUAL_LOCALE:
+ return actual;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+}
+
+void LocaleBased::setLocaleIDs(const char* validID, const char* actualID) {
+ if (validID != 0) {
+ uprv_strcpy(valid, validID);
+ }
+ if (actualID != 0) {
+ uprv_strcpy(actual, actualID);
+ }
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/locbased.h b/Build/source/libs/icu/icu-xetex/common/locbased.h
new file mode 100644
index 00000000000..366b15109e8
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locbased.h
@@ -0,0 +1,97 @@
+/*
+**********************************************************************
+* Copyright (c) 2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: January 16 2004
+* Since: ICU 2.8
+**********************************************************************
+*/
+#ifndef LOCBASED_H
+#define LOCBASED_H
+
+#include "unicode/locid.h"
+#include "unicode/uobject.h"
+
+/**
+ * Macro to declare a locale LocaleBased wrapper object for the given
+ * object, which must have two members named `validLocale' and
+ * `actualLocale'.
+ */
+#define U_LOCALE_BASED(varname, objname) \
+ LocaleBased varname((objname).validLocale, (objname).actualLocale);
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A utility class that unifies the implementation of getLocale() by
+ * various ICU services. This class is likely to be removed in the
+ * ICU 3.0 time frame in favor of an integrated approach with the
+ * services framework.
+ * @since ICU 2.8
+ */
+class U_COMMON_API LocaleBased : public UMemory {
+
+ public:
+
+ /**
+ * Construct a LocaleBased wrapper around the two pointers. These
+ * will be aliased for the lifetime of this object.
+ */
+ inline LocaleBased(char* validAlias, char* actualAlias);
+
+ /**
+ * Construct a LocaleBased wrapper around the two const pointers.
+ * These will be aliased for the lifetime of this object.
+ */
+ inline LocaleBased(const char* validAlias, const char* actualAlias);
+
+ /**
+ * Return locale meta-data for the service object wrapped by this
+ * object. Either the valid or the actual locale may be
+ * retrieved.
+ * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
+ * @param status input-output error code
+ * @return the indicated locale
+ */
+ Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
+ /**
+ * Return the locale ID for the service object wrapped by this
+ * object. Either the valid or the actual locale may be
+ * retrieved.
+ * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
+ * @param status input-output error code
+ * @return the indicated locale ID
+ */
+ const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
+
+ /**
+ * Set the locale meta-data for the service object wrapped by this
+ * object. If either parameter is zero, it is ignored.
+ * @param valid the ID of the valid locale
+ * @param actual the ID of the actual locale
+ */
+ void setLocaleIDs(const char* valid, const char* actual);
+
+ private:
+
+ char* valid;
+
+ char* actual;
+};
+
+inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
+ valid(validAlias), actual(actualAlias) {
+}
+
+inline LocaleBased::LocaleBased(const char* validAlias,
+ const char* actualAlias) :
+ // ugh: cast away const
+ valid((char*)validAlias), actual((char*)actualAlias) {
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/locid.cpp b/Build/source/libs/icu/icu-xetex/common/locid.cpp
new file mode 100644
index 00000000000..848a1d7430a
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locid.cpp
@@ -0,0 +1,1330 @@
+/*
+ **********************************************************************
+ * Copyright (C) 1997-2007, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+*
+* File locid.cpp
+*
+* Created by: Richard Gillam
+*
+* Modification History:
+*
+* Date Name Description
+* 02/11/97 aliu Changed gLocPath to fgDataDirectory and added
+* methods to get and set it.
+* 04/02/97 aliu Made operator!= inline; fixed return value
+* of getName().
+* 04/15/97 aliu Cleanup for AIX/Win32.
+* 04/24/97 aliu Numerous changes per code review.
+* 08/18/98 stephen Changed getDisplayName()
+* Added SIMPLIFIED_CHINESE, TRADITIONAL_CHINESE
+* Added getISOCountries(), getISOLanguages(),
+* getLanguagesForCountry()
+* 03/16/99 bertrand rehaul.
+* 07/21/99 stephen Added U_CFUNC setDefault
+* 11/09/99 weiv Added const char * getName() const;
+* 04/12/00 srl removing unicodestring api's and cached hash code
+* 08/10/01 grhoten Change the static Locales to accessor functions
+******************************************************************************
+*/
+
+
+#include "unicode/locid.h"
+#include "unicode/uloc.h"
+#include "umutex.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uhash.h"
+#include "ucln_cmn.h"
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
+static U_NAMESPACE_QUALIFIER Locale* availableLocaleList = NULL;
+static int32_t availableLocaleListCount;
+typedef enum ELocalePos {
+ eENGLISH,
+ eFRENCH,
+ eGERMAN,
+ eITALIAN,
+ eJAPANESE,
+ eKOREAN,
+ eCHINESE,
+
+ eFRANCE,
+ eGERMANY,
+ eITALY,
+ eJAPAN,
+ eKOREA,
+ eCHINA, /* Alias for PRC */
+ eTAIWAN,
+ eUK,
+ eUS,
+ eCANADA,
+ eCANADA_FRENCH,
+
+
+ //eDEFAULT,
+ eMAX_LOCALES
+} ELocalePos;
+
+U_CFUNC int32_t locale_getKeywords(const char *localeID,
+ char prev,
+ char *keywords, int32_t keywordCapacity,
+ char *values, int32_t valuesCapacity, int32_t *valLen,
+ UBool valuesToo,
+ UErrorCode *status);
+
+static U_NAMESPACE_QUALIFIER Locale *gLocaleCache = NULL;
+static U_NAMESPACE_QUALIFIER Locale *gDefaultLocale = NULL;
+static UHashtable *gDefaultLocalesHashT = NULL;
+
+U_CDECL_BEGIN
+//
+// Deleter function for Locales owned by the default Locale hash table/
+//
+static void U_CALLCONV
+deleteLocale(void *obj) {
+ delete (U_NAMESPACE_QUALIFIER Locale *) obj;
+}
+
+static UBool U_CALLCONV locale_cleanup(void)
+{
+ U_NAMESPACE_USE
+
+ if (availableLocaleList) {
+ delete []availableLocaleList;
+ availableLocaleList = NULL;
+ }
+ availableLocaleListCount = 0;
+
+ if (gLocaleCache) {
+ delete [] gLocaleCache;
+ gLocaleCache = NULL;
+ }
+
+ if (gDefaultLocalesHashT) {
+ uhash_close(gDefaultLocalesHashT); // Automatically deletes all elements, using deleter func.
+ gDefaultLocalesHashT = NULL;
+ }
+ else if (gDefaultLocale) {
+ // The cache wasn't created, and only one default locale was created.
+ delete gDefaultLocale;
+ }
+ gDefaultLocale = NULL;
+
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+//
+// locale_set_default_internal.
+//
+void locale_set_default_internal(const char *id)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UBool canonicalize = FALSE;
+
+ // If given a NULL string for the locale id, grab the default
+ // name from the system.
+ // (Different from most other locale APIs, where a null name means use
+ // the current ICU default locale.)
+ if (id == NULL) {
+ umtx_lock(NULL);
+ id = uprv_getDefaultLocaleID();
+ umtx_unlock(NULL);
+ canonicalize = TRUE; // always canonicalize host ID
+ }
+
+ // put the locale id into a canonical form,
+ // in preparation for looking up this locale in the hash table of
+ // already-created locale objects.
+ //
+ status = U_ZERO_ERROR;
+ char localeNameBuf[512];
+
+ if (canonicalize) {
+ uloc_canonicalize(id, localeNameBuf, sizeof(localeNameBuf)-1, &status);
+ } else {
+ uloc_getName(id, localeNameBuf, sizeof(localeNameBuf)-1, &status);
+ }
+ localeNameBuf[sizeof(localeNameBuf)-1] = 0; // Force null termination in event of
+ // a long name filling the buffer.
+ // (long names are truncated.)
+
+ // Lazy creation of the hash table itself, if needed.
+ UBool isOnlyLocale;
+ UMTX_CHECK(NULL, (gDefaultLocale == NULL), isOnlyLocale);
+ if (isOnlyLocale) {
+ // We haven't seen this locale id before.
+ // Create a new Locale object for it.
+ Locale *newFirstDefault = new Locale(Locale::eBOGUS);
+ if (newFirstDefault == NULL) {
+ // No way to report errors from here.
+ return;
+ }
+ newFirstDefault->init(localeNameBuf, FALSE);
+ umtx_lock(NULL);
+ if (gDefaultLocale == NULL) {
+ gDefaultLocale = newFirstDefault; // Assignment to gDefaultLocale must happen inside mutex
+ newFirstDefault = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
+ }
+ // Else some other thread raced us through here, and set the new Locale.
+ // Use the hash table next.
+ umtx_unlock(NULL);
+ if (newFirstDefault == NULL) {
+ // We were successful in setting the locale, and we were the first one to set it.
+ return;
+ }
+ // else start using the hash table.
+ }
+
+ // Lazy creation of the hash table itself, if needed.
+ UBool hashTableNeedsInit;
+ UMTX_CHECK(NULL, (gDefaultLocalesHashT == NULL), hashTableNeedsInit);
+ if (hashTableNeedsInit) {
+ status = U_ZERO_ERROR;
+ UHashtable *tHashTable = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ uhash_setValueDeleter(tHashTable, deleteLocale);
+ umtx_lock(NULL);
+ if (gDefaultLocalesHashT == NULL) {
+ gDefaultLocalesHashT = tHashTable;
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
+ } else {
+ uhash_close(tHashTable);
+ hashTableNeedsInit = FALSE;
+ }
+ umtx_unlock(NULL);
+ }
+
+ // Hash table lookup, key is the locale full name
+ umtx_lock(NULL);
+ Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf);
+ if (newDefault != NULL) {
+ // We have the requested locale in the hash table already.
+ // Just set it as default. Inside the mutex lock, for those troublesome processors.
+ gDefaultLocale = newDefault;
+ umtx_unlock(NULL);
+ } else {
+ umtx_unlock(NULL);
+ // We haven't seen this locale id before.
+ // Create a new Locale object for it.
+ newDefault = new Locale(Locale::eBOGUS);
+ if (newDefault == NULL) {
+ // No way to report errors from here.
+ return;
+ }
+ newDefault->init(localeNameBuf, FALSE);
+
+ // Add newly created Locale to the hash table of default Locales
+ const char *key = newDefault->getName();
+ U_ASSERT(uprv_strcmp(key, localeNameBuf) == 0);
+ umtx_lock(NULL);
+ Locale *hashTableVal = (Locale *)uhash_get(gDefaultLocalesHashT, key);
+ if (hashTableVal == NULL) {
+ if (hashTableNeedsInit) {
+ // This is the second request to set the locale.
+ // Cache the first one.
+ uhash_put(gDefaultLocalesHashT, (void *)gDefaultLocale->getName(), gDefaultLocale, &status);
+ }
+ uhash_put(gDefaultLocalesHashT, (void *)key, newDefault, &status);
+ gDefaultLocale = newDefault;
+ // ignore errors from hash table insert. (Couldn't do anything anyway)
+ // We can still set the default Locale,
+ // it just wont be cached, and will eventually leak.
+ } else {
+ // Some other thread raced us through here, and got the new Locale
+ // into the hash table before us. Use that one.
+ gDefaultLocale = hashTableVal; // Assignment to gDefaultLocale must happen inside mutex
+ delete newDefault;
+ }
+ umtx_unlock(NULL);
+ }
+}
+U_NAMESPACE_END
+
+/* sfb 07/21/99 */
+U_CFUNC void
+locale_set_default(const char *id)
+{
+ U_NAMESPACE_USE
+ locale_set_default_internal(id);
+}
+/* end */
+
+U_CFUNC const char *
+locale_get_default(void)
+{
+ U_NAMESPACE_USE
+
+ return Locale::getDefault().getName();
+}
+
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Locale)
+
+/*Character separating the posix id fields*/
+// '_'
+// In the platform codepage.
+#define SEP_CHAR '_'
+
+Locale::~Locale()
+{
+ /*if fullName is on the heap, we free it*/
+ if (fullName != fullNameBuffer)
+ {
+ uprv_free(fullName);
+ fullName = NULL;
+ }
+ if (baseName && baseName != baseNameBuffer) {
+ uprv_free(baseName);
+ baseName = NULL;
+ }
+}
+
+Locale::Locale()
+ : UObject(), fullName(fullNameBuffer), baseName(NULL)
+{
+ init(NULL, FALSE);
+}
+
+/*
+ * Internal constructor to allow construction of a locale object with
+ * NO side effects. (Default constructor tries to get
+ * the default locale.)
+ */
+Locale::Locale(Locale::ELocaleType)
+ : UObject(), fullName(fullNameBuffer), baseName(NULL)
+{
+ setToBogus();
+}
+
+
+Locale::Locale( const char * newLanguage,
+ const char * newCountry,
+ const char * newVariant,
+ const char * newKeywords)
+ : UObject(), fullName(fullNameBuffer), baseName(NULL)
+{
+ if( (newLanguage==NULL) && (newCountry == NULL) && (newVariant == NULL) )
+ {
+ init(NULL, FALSE); /* shortcut */
+ }
+ else
+ {
+ char togo_stack[ULOC_FULLNAME_CAPACITY];
+ char *togo;
+ char *togo_heap = NULL;
+ int32_t size = 0;
+ int32_t lsize = 0;
+ int32_t csize = 0;
+ int32_t vsize = 0;
+ int32_t ksize = 0;
+ char *p;
+
+ // Calculate the size of the resulting string.
+
+ // Language
+ if ( newLanguage != NULL )
+ {
+ lsize = (int32_t)uprv_strlen(newLanguage);
+ size = lsize;
+ }
+
+ // _Country
+ if ( newCountry != NULL )
+ {
+ csize = (int32_t)uprv_strlen(newCountry);
+ size += csize;
+ }
+
+ // _Variant
+ if ( newVariant != NULL )
+ {
+ // remove leading _'s
+ while(newVariant[0] == SEP_CHAR)
+ {
+ newVariant++;
+ }
+
+ // remove trailing _'s
+ vsize = (int32_t)uprv_strlen(newVariant);
+ while( (vsize>1) && (newVariant[vsize-1] == SEP_CHAR) )
+ {
+ vsize--;
+ }
+ }
+
+ if( vsize > 0 )
+ {
+ size += vsize;
+ }
+
+ // Separator rules:
+ if ( vsize > 0 )
+ {
+ size += 2; // at least: __v
+ }
+ else if ( csize > 0 )
+ {
+ size += 1; // at least: _v
+ }
+
+ if ( newKeywords != NULL)
+ {
+ ksize = (int32_t)uprv_strlen(newKeywords);
+ size += ksize + 1;
+ }
+
+
+ // NOW we have the full locale string..
+
+ /*if the whole string is longer than our internal limit, we need
+ to go to the heap for temporary buffers*/
+ if (size >= ULOC_FULLNAME_CAPACITY)
+ {
+ togo_heap = (char *)uprv_malloc(sizeof(char)*(size+1));
+ togo = togo_heap;
+ }
+ else
+ {
+ togo = togo_stack;
+ }
+
+ togo[0] = 0;
+
+ // Now, copy it back.
+ p = togo;
+ if ( lsize != 0 )
+ {
+ uprv_strcpy(p, newLanguage);
+ p += lsize;
+ }
+
+ if ( ( vsize != 0 ) || (csize != 0) ) // at least: __v
+ { // ^
+ *p++ = SEP_CHAR;
+ }
+
+ if ( csize != 0 )
+ {
+ uprv_strcpy(p, newCountry);
+ p += csize;
+ }
+
+ if ( vsize != 0)
+ {
+ *p++ = SEP_CHAR; // at least: __v
+
+ uprv_strncpy(p, newVariant, vsize); // Must use strncpy because
+ p += vsize; // of trimming (above).
+ *p = 0; // terminate
+ }
+
+ if ( ksize != 0)
+ {
+ if (uprv_strchr(newKeywords, '=')) {
+ *p++ = '@'; /* keyword parsing */
+ }
+ else {
+ *p++ = '_'; /* Variant parsing with a script */
+ if ( vsize == 0) {
+ *p++ = '_'; /* No country found */
+ }
+ }
+ uprv_strcpy(p, newKeywords);
+ p += ksize;
+ }
+
+ // Parse it, because for example 'language' might really be a complete
+ // string.
+ init(togo, FALSE);
+
+ if (togo_heap) {
+ uprv_free(togo_heap);
+ }
+ }
+}
+
+Locale::Locale(const Locale &other)
+ : UObject(other), fullName(fullNameBuffer), baseName(NULL)
+{
+ *this = other;
+}
+
+Locale &Locale::operator=(const Locale &other)
+{
+ if (this == &other) {
+ return *this;
+ }
+
+ if (&other == NULL) {
+ this->setToBogus();
+ return *this;
+ }
+
+ /* Free our current storage */
+ if(fullName != fullNameBuffer) {
+ uprv_free(fullName);
+ fullName = fullNameBuffer;
+ }
+
+ /* Allocate the full name if necessary */
+ if(other.fullName != other.fullNameBuffer) {
+ fullName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(other.fullName)+1));
+ }
+ /* Copy the full name */
+ uprv_strcpy(fullName, other.fullName);
+
+ /* baseName is the cached result of getBaseName. if 'other' has a
+ baseName and it fits in baseNameBuffer, then copy it. otherwise set
+ it to NULL, and let the user lazy-create it (in getBaseName) if they
+ want it. */
+ if(baseName && baseName != baseNameBuffer) {
+ uprv_free(baseName);
+ }
+ baseName = NULL;
+
+ if(other.baseName == other.baseNameBuffer) {
+ uprv_strcpy(baseNameBuffer, other.baseNameBuffer);
+ baseName = baseNameBuffer;
+ }
+
+ /* Copy the language and country fields */
+ uprv_strcpy(language, other.language);
+ uprv_strcpy(script, other.script);
+ uprv_strcpy(country, other.country);
+
+ /* The variantBegin is an offset into fullName, just copy it */
+ variantBegin = other.variantBegin;
+ fIsBogus = other.fIsBogus;
+ return *this;
+}
+
+Locale *
+Locale::clone() const {
+ return new Locale(*this);
+}
+
+UBool
+Locale::operator==( const Locale& other) const
+{
+ return (uprv_strcmp(other.fullName, fullName) == 0);
+}
+
+/*This function initializes a Locale from a C locale ID*/
+Locale& Locale::init(const char* localeID, UBool canonicalize)
+{
+ fIsBogus = FALSE;
+ /* Free our current storage */
+ if(fullName != fullNameBuffer) {
+ uprv_free(fullName);
+ fullName = fullNameBuffer;
+ }
+
+ if(baseName && baseName != baseNameBuffer) {
+ uprv_free(baseName);
+ baseName = NULL;
+ }
+
+ // not a loop:
+ // just an easy way to have a common error-exit
+ // without goto and without another function
+ do {
+ char *separator;
+ char *field[5] = {0};
+ int32_t fieldLen[5] = {0};
+ int32_t fieldIdx;
+ int32_t variantField;
+ int32_t length;
+ UErrorCode err;
+
+ if(localeID == NULL) {
+ // not an error, just set the default locale
+ return *this = getDefault();
+ }
+
+ /* preset all fields to empty */
+ language[0] = script[0] = country[0] = 0;
+
+ // "canonicalize" the locale ID to ICU/Java format
+ err = U_ZERO_ERROR;
+ length = canonicalize ?
+ uloc_canonicalize(localeID, fullName, sizeof(fullNameBuffer), &err) :
+ uloc_getName(localeID, fullName, sizeof(fullNameBuffer), &err);
+
+ if(err == U_BUFFER_OVERFLOW_ERROR || length >= (int32_t)sizeof(fullNameBuffer)) {
+ /*Go to heap for the fullName if necessary*/
+ fullName = (char *)uprv_malloc(sizeof(char)*(length + 1));
+ if(fullName == 0) {
+ fullName = fullNameBuffer;
+ break; // error: out of memory
+ }
+ err = U_ZERO_ERROR;
+ length = canonicalize ?
+ uloc_canonicalize(localeID, fullName, length+1, &err) :
+ uloc_getName(localeID, fullName, length+1, &err);
+ }
+ if(U_FAILURE(err) || err == U_STRING_NOT_TERMINATED_WARNING) {
+ /* should never occur */
+ break;
+ }
+
+ variantBegin = length;
+
+ /* after uloc_getName/canonicalize() we know that only '_' are separators */
+ separator = field[0] = fullName;
+ fieldIdx = 1;
+ while ((separator = uprv_strchr(field[fieldIdx-1], SEP_CHAR)) && fieldIdx < (int32_t)(sizeof(field)/sizeof(field[0]))-1) {
+ field[fieldIdx] = separator + 1;
+ fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]);
+ fieldIdx++;
+ }
+ // variant may contain @foo or .foo POSIX cruft; remove it
+ separator = uprv_strchr(field[fieldIdx-1], '@');
+ char* sep2 = uprv_strchr(field[fieldIdx-1], '.');
+ if (separator!=NULL || sep2!=NULL) {
+ if (separator==NULL || (sep2!=NULL && separator > sep2)) {
+ separator = sep2;
+ }
+ fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]);
+ } else {
+ fieldLen[fieldIdx-1] = length - (int32_t)(field[fieldIdx-1] - fullName);
+ }
+
+ if (fieldLen[0] >= (int32_t)(sizeof(language))
+ || (fieldLen[1] == 4 && fieldLen[2] >= (int32_t)(sizeof(country)))
+ || (fieldLen[1] != 4 && fieldLen[1] >= (int32_t)(sizeof(country))))
+ {
+ break; // error: one of the fields is too long
+ }
+
+ variantField = 2; /* Usually the 2nd one, except when a script is used. */
+ if (fieldLen[0] > 0) {
+ /* We have a language */
+ uprv_memcpy(language, fullName, fieldLen[0]);
+ language[fieldLen[0]] = 0;
+ }
+ if (fieldLen[1] == 4) {
+ /* We have at least a script */
+ uprv_memcpy(script, field[1], fieldLen[1]);
+ script[fieldLen[1]] = 0;
+ variantField = 3;
+ if (fieldLen[2] > 0) {
+ /* We have a country */
+ uprv_memcpy(country, field[2], fieldLen[2]);
+ country[fieldLen[2]] = 0;
+ }
+ }
+ else if (fieldLen[1] > 0) {
+ /* We have a country and no script */
+ uprv_memcpy(country, field[1], fieldLen[1]);
+ country[fieldLen[1]] = 0;
+ }
+ if (variantField > 0 && fieldLen[variantField] > 0) {
+ /* We have a variant */
+ variantBegin = (int32_t)(field[variantField] - fullName);
+ }
+
+ // successful end of init()
+ return *this;
+ } while(0); /*loop doesn't iterate*/
+
+ // when an error occurs, then set this object to "bogus" (there is no UErrorCode here)
+ setToBogus();
+
+ return *this;
+}
+
+int32_t
+Locale::hashCode() const
+{
+ UHashTok hashKey;
+ hashKey.pointer = fullName;
+ return uhash_hashChars(hashKey);
+}
+
+void
+Locale::setToBogus() {
+ /* Free our current storage */
+ if(fullName != fullNameBuffer) {
+ uprv_free(fullName);
+ fullName = fullNameBuffer;
+ }
+ *fullNameBuffer = 0;
+ *language = 0;
+ *script = 0;
+ *country = 0;
+ fIsBogus = TRUE;
+}
+
+const Locale& U_EXPORT2
+Locale::getDefault()
+{
+ const Locale *retLocale;
+ UMTX_CHECK(NULL, gDefaultLocale, retLocale);
+ if (retLocale == NULL) {
+ locale_set_default_internal(NULL);
+ umtx_lock(NULL);
+ // Need a mutex in case some other thread set a new
+ // default inbetween when we set and when we get the new default. For
+ // processors with weak memory coherency, we might not otherwise see all
+ // of the newly created new default locale.
+ retLocale = gDefaultLocale;
+ umtx_unlock(NULL);
+ }
+ return *retLocale;
+}
+
+
+
+void U_EXPORT2
+Locale::setDefault( const Locale& newLocale,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ /* Set the default from the full name string of the supplied locale.
+ * This is a convenient way to access the default locale caching mechanisms.
+ */
+ const char *localeID = newLocale.getName();
+ locale_set_default_internal(localeID);
+}
+
+Locale U_EXPORT2
+Locale::createFromName (const char *name)
+{
+ if (name) {
+ Locale l("");
+ l.init(name, FALSE);
+ return l;
+ }
+ else {
+ return getDefault();
+ }
+}
+
+Locale U_EXPORT2
+Locale::createCanonical(const char* name) {
+ Locale loc("");
+ loc.init(name, TRUE);
+ return loc;
+}
+
+const char *
+Locale::getISO3Language() const
+{
+ return uloc_getISO3Language(fullName);
+}
+
+
+const char *
+Locale::getISO3Country() const
+{
+ return uloc_getISO3Country(fullName);
+}
+
+/**
+ * Return the LCID value as specified in the "LocaleID" resource for this
+ * locale. The LocaleID must be expressed as a hexadecimal number, from
+ * one to four digits. If the LocaleID resource is not present, or is
+ * in an incorrect format, 0 is returned. The LocaleID is for use in
+ * Windows (it is an LCID), but is available on all platforms.
+ */
+uint32_t
+Locale::getLCID() const
+{
+ return uloc_getLCID(fullName);
+}
+
+UnicodeString&
+Locale::getDisplayLanguage(UnicodeString& dispLang) const
+{
+ return this->getDisplayLanguage(getDefault(), dispLang);
+}
+
+/*We cannot make any assumptions on the size of the output display strings
+* Yet, since we are calling through to a C API, we need to set limits on
+* buffer size. For all the following getDisplay functions we first attempt
+* to fill up a stack allocated buffer. If it is to small we heap allocated
+* the exact buffer we need copy it to the UnicodeString and delete it*/
+
+UnicodeString&
+Locale::getDisplayLanguage(const Locale &displayLocale,
+ UnicodeString &result) const {
+ UChar *buffer;
+ UErrorCode errorCode=U_ZERO_ERROR;
+ int32_t length;
+
+ buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+
+ length=uloc_getDisplayLanguage(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ buffer=result.getBuffer(length);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uloc_getDisplayLanguage(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ return result;
+}
+
+UnicodeString&
+Locale::getDisplayScript(UnicodeString& dispScript) const
+{
+ return this->getDisplayScript(getDefault(), dispScript);
+}
+
+UnicodeString&
+Locale::getDisplayScript(const Locale &displayLocale,
+ UnicodeString &result) const {
+ UChar *buffer;
+ UErrorCode errorCode=U_ZERO_ERROR;
+ int32_t length;
+
+ buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+
+ length=uloc_getDisplayScript(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ buffer=result.getBuffer(length);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uloc_getDisplayScript(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ return result;
+}
+
+UnicodeString&
+Locale::getDisplayCountry(UnicodeString& dispCntry) const
+{
+ return this->getDisplayCountry(getDefault(), dispCntry);
+}
+
+UnicodeString&
+Locale::getDisplayCountry(const Locale &displayLocale,
+ UnicodeString &result) const {
+ UChar *buffer;
+ UErrorCode errorCode=U_ZERO_ERROR;
+ int32_t length;
+
+ buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+
+ length=uloc_getDisplayCountry(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ buffer=result.getBuffer(length);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uloc_getDisplayCountry(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ return result;
+}
+
+UnicodeString&
+Locale::getDisplayVariant(UnicodeString& dispVar) const
+{
+ return this->getDisplayVariant(getDefault(), dispVar);
+}
+
+UnicodeString&
+Locale::getDisplayVariant(const Locale &displayLocale,
+ UnicodeString &result) const {
+ UChar *buffer;
+ UErrorCode errorCode=U_ZERO_ERROR;
+ int32_t length;
+
+ buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+
+ length=uloc_getDisplayVariant(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ buffer=result.getBuffer(length);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uloc_getDisplayVariant(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ return result;
+}
+
+UnicodeString&
+Locale::getDisplayName( UnicodeString& name ) const
+{
+ return this->getDisplayName(getDefault(), name);
+}
+
+UnicodeString&
+Locale::getDisplayName(const Locale &displayLocale,
+ UnicodeString &result) const {
+ UChar *buffer;
+ UErrorCode errorCode=U_ZERO_ERROR;
+ int32_t length;
+
+ buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+
+ length=uloc_getDisplayName(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ buffer=result.getBuffer(length);
+ if(buffer==0) {
+ result.truncate(0);
+ return result;
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uloc_getDisplayName(fullName, displayLocale.fullName,
+ buffer, result.getCapacity(),
+ &errorCode);
+ result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ return result;
+}
+const Locale* U_EXPORT2
+Locale::getAvailableLocales(int32_t& count)
+{
+ // for now, there is a hardcoded list, so just walk through that list and set it up.
+ UBool needInit;
+ UMTX_CHECK(NULL, availableLocaleList == NULL, needInit);
+
+ if (needInit) {
+ int32_t locCount = uloc_countAvailable();
+ Locale *newLocaleList = 0;
+ if(locCount) {
+ newLocaleList = new Locale[locCount];
+ }
+ if (newLocaleList == NULL) {
+ count = 0;
+ return NULL;
+ }
+
+ count = locCount;
+
+ while(--locCount >= 0) {
+ newLocaleList[locCount].setFromPOSIXID(uloc_getAvailable(locCount));
+ }
+
+ umtx_lock(NULL);
+ if(availableLocaleList == 0) {
+ availableLocaleListCount = count;
+ availableLocaleList = newLocaleList;
+ newLocaleList = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
+ }
+ umtx_unlock(NULL);
+ delete []newLocaleList;
+ }
+ count = availableLocaleListCount;
+ return availableLocaleList;
+}
+
+const char* const* U_EXPORT2 Locale::getISOCountries()
+{
+ return uloc_getISOCountries();
+}
+
+const char* const* U_EXPORT2 Locale::getISOLanguages()
+{
+ return uloc_getISOLanguages();
+}
+
+// Set the locale's data based on a posix id.
+void Locale::setFromPOSIXID(const char *posixID)
+{
+ init(posixID, TRUE);
+}
+
+const Locale & U_EXPORT2
+Locale::getEnglish(void)
+{
+ return getLocale(eENGLISH);
+}
+
+const Locale & U_EXPORT2
+Locale::getFrench(void)
+{
+ return getLocale(eFRENCH);
+}
+
+const Locale & U_EXPORT2
+Locale::getGerman(void)
+{
+ return getLocale(eGERMAN);
+}
+
+const Locale & U_EXPORT2
+Locale::getItalian(void)
+{
+ return getLocale(eITALIAN);
+}
+
+const Locale & U_EXPORT2
+Locale::getJapanese(void)
+{
+ return getLocale(eJAPANESE);
+}
+
+const Locale & U_EXPORT2
+Locale::getKorean(void)
+{
+ return getLocale(eKOREAN);
+}
+
+const Locale & U_EXPORT2
+Locale::getChinese(void)
+{
+ return getLocale(eCHINESE);
+}
+
+const Locale & U_EXPORT2
+Locale::getSimplifiedChinese(void)
+{
+ return getLocale(eCHINA);
+}
+
+const Locale & U_EXPORT2
+Locale::getTraditionalChinese(void)
+{
+ return getLocale(eTAIWAN);
+}
+
+
+const Locale & U_EXPORT2
+Locale::getFrance(void)
+{
+ return getLocale(eFRANCE);
+}
+
+const Locale & U_EXPORT2
+Locale::getGermany(void)
+{
+ return getLocale(eGERMANY);
+}
+
+const Locale & U_EXPORT2
+Locale::getItaly(void)
+{
+ return getLocale(eITALY);
+}
+
+const Locale & U_EXPORT2
+Locale::getJapan(void)
+{
+ return getLocale(eJAPAN);
+}
+
+const Locale & U_EXPORT2
+Locale::getKorea(void)
+{
+ return getLocale(eKOREA);
+}
+
+const Locale & U_EXPORT2
+Locale::getChina(void)
+{
+ return getLocale(eCHINA);
+}
+
+const Locale & U_EXPORT2
+Locale::getPRC(void)
+{
+ return getLocale(eCHINA);
+}
+
+const Locale & U_EXPORT2
+Locale::getTaiwan(void)
+{
+ return getLocale(eTAIWAN);
+}
+
+const Locale & U_EXPORT2
+Locale::getUK(void)
+{
+ return getLocale(eUK);
+}
+
+const Locale & U_EXPORT2
+Locale::getUS(void)
+{
+ return getLocale(eUS);
+}
+
+const Locale & U_EXPORT2
+Locale::getCanada(void)
+{
+ return getLocale(eCANADA);
+}
+
+const Locale & U_EXPORT2
+Locale::getCanadaFrench(void)
+{
+ return getLocale(eCANADA_FRENCH);
+}
+
+const Locale &
+Locale::getLocale(int locid)
+{
+ Locale *localeCache = getLocaleCache();
+ U_ASSERT((locid < eMAX_LOCALES)&&(locid>=0));
+ if (localeCache == NULL) {
+ // Failure allocating the locale cache.
+ // The best we can do is return a NULL reference.
+ locid = 0;
+ }
+ return localeCache[locid]; /*operating on NULL*/
+}
+
+/*
+This function is defined this way in order to get around static
+initialization and static destruction.
+ */
+Locale *
+Locale::getLocaleCache(void)
+{
+ umtx_lock(NULL);
+ UBool needInit = (gLocaleCache == NULL);
+ umtx_unlock(NULL);
+
+ if (needInit) {
+ Locale *tLocaleCache = new Locale[(int)eMAX_LOCALES];
+ if (tLocaleCache == NULL) {
+ return NULL;
+ }
+ tLocaleCache[eENGLISH] = Locale("en");
+ tLocaleCache[eFRENCH] = Locale("fr");
+ tLocaleCache[eGERMAN] = Locale("de");
+ tLocaleCache[eITALIAN] = Locale("it");
+ tLocaleCache[eJAPANESE] = Locale("ja");
+ tLocaleCache[eKOREAN] = Locale("ko");
+ tLocaleCache[eCHINESE] = Locale("zh");
+ tLocaleCache[eFRANCE] = Locale("fr", "FR");
+ tLocaleCache[eGERMANY] = Locale("de", "DE");
+ tLocaleCache[eITALY] = Locale("it", "IT");
+ tLocaleCache[eJAPAN] = Locale("ja", "JP");
+ tLocaleCache[eKOREA] = Locale("ko", "KR");
+ tLocaleCache[eCHINA] = Locale("zh", "CN");
+ tLocaleCache[eTAIWAN] = Locale("zh", "TW");
+ tLocaleCache[eUK] = Locale("en", "GB");
+ tLocaleCache[eUS] = Locale("en", "US");
+ tLocaleCache[eCANADA] = Locale("en", "CA");
+ tLocaleCache[eCANADA_FRENCH] = Locale("fr", "CA");
+
+ umtx_lock(NULL);
+ if (gLocaleCache == NULL) {
+ gLocaleCache = tLocaleCache;
+ tLocaleCache = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
+ }
+ umtx_unlock(NULL);
+ if (tLocaleCache) {
+ delete [] tLocaleCache; // Fancy array delete will destruct each member.
+ }
+ }
+ return gLocaleCache;
+}
+
+class KeywordEnumeration : public StringEnumeration {
+private:
+ char *keywords;
+ char *current;
+ int32_t length;
+ UnicodeString currUSKey;
+ static const char fgClassID;/* Warning this is used beyond the typical RTTI usage. */
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void) { return (UClassID)&fgClassID; }
+ virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); }
+public:
+ KeywordEnumeration(const char *keys, int32_t keywordLen, int32_t currentIndex, UErrorCode &status)
+ : keywords((char *)&fgClassID), current((char *)&fgClassID), length(0) {
+ if(U_SUCCESS(status) && keywordLen != 0) {
+ if(keys == NULL || keywordLen < 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ keywords = (char *)uprv_malloc(keywordLen+1);
+ if (keywords == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else {
+ uprv_memcpy(keywords, keys, keywordLen);
+ keywords[keywordLen] = 0;
+ current = keywords + currentIndex;
+ length = keywordLen;
+ }
+ }
+ }
+ }
+
+ virtual ~KeywordEnumeration() {
+ uprv_free(keywords);
+ }
+
+ virtual StringEnumeration * clone() const
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ return new KeywordEnumeration(keywords, length, (int32_t)(current - keywords), status);
+ }
+
+ virtual int32_t count(UErrorCode &/*status*/) const {
+ char *kw = keywords;
+ int32_t result = 0;
+ while(*kw) {
+ result++;
+ kw += uprv_strlen(kw)+1;
+ }
+ return result;
+ }
+
+ virtual const char* next(int32_t* resultLength, UErrorCode& status) {
+ const char* result;
+ int32_t len;
+ if(U_SUCCESS(status) && *current != 0) {
+ result = current;
+ len = (int32_t)uprv_strlen(current);
+ current += len+1;
+ if(resultLength != NULL) {
+ *resultLength = len;
+ }
+ } else {
+ if(resultLength != NULL) {
+ *resultLength = 0;
+ }
+ result = NULL;
+ }
+ return result;
+ }
+
+ virtual const UnicodeString* snext(UErrorCode& status) {
+ int32_t resultLength = 0;
+ const char *s = next(&resultLength, status);
+ return setChars(s, resultLength, status);
+ }
+
+ virtual void reset(UErrorCode& /*status*/) {
+ current = keywords;
+ }
+};
+
+const char KeywordEnumeration::fgClassID = '\0';
+
+StringEnumeration *
+Locale::createKeywords(UErrorCode &status) const
+{
+ char keywords[256];
+ int32_t keywordCapacity = 256;
+ StringEnumeration *result = NULL;
+
+ const char* variantStart = uprv_strchr(fullName, '@');
+ const char* assignment = uprv_strchr(fullName, '=');
+ if(variantStart) {
+ if(assignment > variantStart) {
+ int32_t keyLen = locale_getKeywords(variantStart+1, '@', keywords, keywordCapacity, NULL, 0, NULL, FALSE, &status);
+ if(keyLen) {
+ result = new KeywordEnumeration(keywords, keyLen, 0, status);
+ }
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ return result;
+}
+
+int32_t
+Locale::getKeywordValue(const char* keywordName, char *buffer, int32_t bufLen, UErrorCode &status) const
+{
+ return uloc_getKeywordValue(fullName, keywordName, buffer, bufLen, &status);
+}
+
+const char *
+Locale::getBaseName() const
+{
+ // lazy init
+ UErrorCode status = U_ZERO_ERROR;
+ // semantically const
+ if(baseName == 0) {
+ ((Locale *)this)->baseName = ((Locale *)this)->baseNameBuffer;
+ int32_t baseNameSize = uloc_getBaseName(fullName, baseName, ULOC_FULLNAME_CAPACITY, &status);
+ if(baseNameSize >= ULOC_FULLNAME_CAPACITY) {
+ ((Locale *)this)->baseName = (char *)uprv_malloc(sizeof(char) * baseNameSize + 1);
+ uloc_getBaseName(fullName, baseName, baseNameSize+1, &status);
+ }
+ baseName[baseNameSize] = 0;
+ }
+ return baseName;
+}
+
+
+//eof
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/locmap.c b/Build/source/libs/icu/icu-xetex/common/locmap.c
new file mode 100644
index 00000000000..802c6c38c17
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locmap.c
@@ -0,0 +1,893 @@
+/*
+ **********************************************************************
+ * Copyright (C) 1996-2006, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ *
+ * Provides functionality for mapping between
+ * LCID and Posix IDs or ICU locale to codepage
+ *
+ * Note: All classes and code in this file are
+ * intended for internal use only.
+ *
+ * Methods of interest:
+ * unsigned long convertToLCID(const char*);
+ * const char* convertToPosix(unsigned long);
+ *
+ * Kathleen Wilson, 4/30/96
+ *
+ * Date Name Description
+ * 3/11/97 aliu Fixed off-by-one bug in assignment operator. Added
+ * setId() method and safety check against
+ * MAX_ID_LENGTH.
+ * 04/23/99 stephen Added C wrapper for convertToPosix.
+ * 09/18/00 george Removed the memory leaks.
+ * 08/23/01 george Convert to C
+ */
+
+#include "locmap.h"
+#include "cstring.h"
+
+/*
+ * Note:
+ * The mapping from Win32 locale ID numbers to POSIX locale strings should
+ * be the faster one.
+ *
+ * Many LCID values come from winnt.h
+ * Some also come from http://www.microsoft.com/globaldev/reference/lcid-all.mspx
+ */
+
+/*
+////////////////////////////////////////////////
+//
+// Internal Classes for LCID <--> POSIX Mapping
+//
+/////////////////////////////////////////////////
+*/
+
+typedef struct ILcidPosixElement
+{
+ const uint32_t hostID;
+ const char * const posixID;
+} ILcidPosixElement;
+
+typedef struct ILcidPosixMap
+{
+ const uint32_t numRegions;
+ const struct ILcidPosixElement* const regionMaps;
+} ILcidPosixMap;
+
+
+/*
+/////////////////////////////////////////////////
+//
+// Easy macros to make the LCID <--> POSIX Mapping
+//
+/////////////////////////////////////////////////
+*/
+
+/*
+ The standard one language/one country mapping for LCID.
+ The first element must be the language, and the following
+ elements are the language with the country.
+ */
+#define ILCID_POSIX_ELEMENT_ARRAY(hostID, languageID, posixID) \
+static const ILcidPosixElement languageID[] = { \
+ {LANGUAGE_LCID(hostID), #languageID}, /* parent locale */ \
+ {hostID, #posixID}, \
+};
+
+/*
+ Create the map for the posixID. This macro supposes that the language string
+ name is the same as the global variable name, and that the first element
+ in the ILcidPosixElement is just the language.
+ */
+#define ILCID_POSIX_MAP(_posixID) \
+ {sizeof(_posixID)/sizeof(ILcidPosixElement), _posixID}
+
+/*
+////////////////////////////////////////////
+//
+// Create the table of LCID to POSIX Mapping
+// None of it should be dynamically created.
+//
+// Keep static locale variables inside the function so that
+// it can be created properly during static init.
+//
+////////////////////////////////////////////
+*/
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0436, af, af_ZA)
+
+static const ILcidPosixElement ar[] = {
+ {0x01, "ar"},
+ {0x3801, "ar_AE"},
+ {0x3c01, "ar_BH"},
+ {0x1401, "ar_DZ"},
+ {0x0c01, "ar_EG"},
+ {0x0801, "ar_IQ"},
+ {0x2c01, "ar_JO"},
+ {0x3401, "ar_KW"},
+ {0x3001, "ar_LB"},
+ {0x1001, "ar_LY"},
+ {0x1801, "ar_MA"},
+ {0x2001, "ar_OM"},
+ {0x4001, "ar_QA"},
+ {0x0401, "ar_SA"},
+ {0x2801, "ar_SY"},
+ {0x1c01, "ar_TN"},
+ {0x2401, "ar_YE"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x044d, as, as_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x045e, am, am_ET)
+ILCID_POSIX_ELEMENT_ARRAY(0x047a, arn,arn_CL)
+
+static const ILcidPosixElement az[] = {
+ {0x2c, "az"},
+ {0x082c, "az_Cyrl_AZ"}, /* Cyrillic based */
+ {0x082c, "az_Cyrl"}, /* Cyrillic based */
+ {0x042c, "az_Latn_AZ"}, /* Latin based */
+ {0x042c, "az_Latn"}, /* Latin based */
+ {0x042c, "az_AZ"} /* Latin based */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x046d, ba, ba_RU)
+ILCID_POSIX_ELEMENT_ARRAY(0x0423, be, be_BY)
+
+static const ILcidPosixElement ber[] = {
+ {0x5f, "ber"},
+ {0x045f, "ber_Arab_DZ"},
+ {0x045f, "ber_Arab"},
+ {0x085f, "ber_Latn_DZ"},
+ {0x085f, "ber_Latn"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0402, bg, bg_BG)
+
+static const ILcidPosixElement bn[] = {
+ {0x45, "bn"},
+ {0x0845, "bn_BD"},
+ {0x0445, "bn_IN"}
+};
+
+static const ILcidPosixElement bo[] = {
+ {0x51, "bo"},
+ {0x0851, "bo_BT"},
+ {0x0451, "bo_CN"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x047e, br, br_FR)
+ILCID_POSIX_ELEMENT_ARRAY(0x0403, ca, ca_ES)
+ILCID_POSIX_ELEMENT_ARRAY(0x0483, co, co_FR)
+ILCID_POSIX_ELEMENT_ARRAY(0x045c, chr,chr_US)
+
+/* Declared as cs_CZ to get around compiler errors on z/OS, which defines cs as a function */
+static const ILcidPosixElement cs_CZ[] = {
+ {0x05, "cs"},
+ {0x0405, "cs_CZ"},
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0452, cy, cy_GB)
+ILCID_POSIX_ELEMENT_ARRAY(0x0406, da, da_DK)
+
+static const ILcidPosixElement de[] = {
+ {0x07, "de"},
+ {0x0c07, "de_AT"},
+ {0x0807, "de_CH"},
+ {0x0407, "de_DE"},
+ {0x1407, "de_LI"},
+ {0x1007, "de_LU"},
+ {0x10407,"de_DE@collation=phonebook"}, /*This is really de_DE_PHONEBOOK on Windows*/
+ {0x10407,"de@collation=phonebook"} /*This is really de_DE_PHONEBOOK on Windows*/
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0465, dv, dv_MV)
+ILCID_POSIX_ELEMENT_ARRAY(0x0408, el, el_GR)
+
+static const ILcidPosixElement en[] = {
+ {0x09, "en"},
+ {0x0c09, "en_AU"},
+ {0x2809, "en_BZ"},
+ {0x1009, "en_CA"},
+ {0x0809, "en_GB"},
+ {0x1809, "en_IE"},
+ {0x4009, "en_IN"},
+ {0x2009, "en_JM"},
+ {0x4409, "en_MY"},
+ {0x1409, "en_NZ"},
+ {0x3409, "en_PH"},
+ {0x4809, "en_SG"},
+ {0x2C09, "en_TT"},
+ {0x0409, "en_US"},
+ {0x007f, "en_US_POSIX"}, /* duplicate for roundtripping */
+ {0x2409, "en_VI"}, /* Virgin Islands AKA Caribbean Islands (en_CB). */
+ {0x1c09, "en_ZA"},
+ {0x3009, "en_ZW"},
+ {0x0409, "en_AS"}, /* Alias for en_US. Leave last. */
+ {0x0409, "en_GU"}, /* Alias for en_US. Leave last. */
+ {0x0409, "en_MH"}, /* Alias for en_US. Leave last. */
+ {0x0409, "en_MP"}, /* Alias for en_US. Leave last. */
+ {0x0409, "en_UM"} /* Alias for en_US. Leave last. */
+};
+
+static const ILcidPosixElement en_US_POSIX[] = {
+ {0x007f, "en_US_POSIX"} /* duplicate for roundtripping */
+};
+
+static const ILcidPosixElement es[] = {
+ {0x0a, "es"},
+ {0x2c0a, "es_AR"},
+ {0x400a, "es_BO"},
+ {0x340a, "es_CL"},
+ {0x240a, "es_CO"},
+ {0x140a, "es_CR"},
+ {0x1c0a, "es_DO"},
+ {0x300a, "es_EC"},
+ {0x0c0a, "es_ES"}, /*Modern sort.*/
+ {0x100a, "es_GT"},
+ {0x480a, "es_HN"},
+ {0x080a, "es_MX"},
+ {0x4c0a, "es_NI"},
+ {0x180a, "es_PA"},
+ {0x280a, "es_PE"},
+ {0x500a, "es_PR"},
+ {0x3c0a, "es_PY"},
+ {0x440a, "es_SV"},
+ {0x540a, "es_US"},
+ {0x380a, "es_UY"},
+ {0x200a, "es_VE"},
+ {0x040a, "es_ES@collation=traditional"},
+ {0x040a, "es@collation=traditional"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0425, et, et_EE)
+ILCID_POSIX_ELEMENT_ARRAY(0x042d, eu, eu_ES)
+
+/* ISO-639 doesn't distinguish between Persian and Dari.*/
+static const ILcidPosixElement fa[] = {
+ {0x29, "fa"},
+ {0x0429, "fa_IR"}, /* Persian/Farsi (Iran) */
+ {0x048c, "fa_AF"} /* Persian/Dari (Afghanistan) */
+};
+
+/* duplicate for roundtripping */
+static const ILcidPosixElement fa_AF[] = {
+ {0x8c, "fa_AF"}, /* Persian/Dari (Afghanistan) */
+ {0x048c, "fa_AF"} /* Persian/Dari (Afghanistan) */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x040b, fi, fi_FI)
+ILCID_POSIX_ELEMENT_ARRAY(0x0464, fil,fil_PH)
+ILCID_POSIX_ELEMENT_ARRAY(0x0438, fo, fo_FO)
+
+static const ILcidPosixElement fr[] = {
+ {0x0c, "fr"},
+ {0x080c, "fr_BE"},
+ {0x0c0c, "fr_CA"},
+ {0x240c, "fr_CD"},
+ {0x100c, "fr_CH"},
+ {0x300c, "fr_CI"},
+ {0x2c0c, "fr_CM"},
+ {0x040c, "fr_FR"},
+ {0x3c0c, "fr_HT"},
+ {0x140c, "fr_LU"},
+ {0x380c, "fr_MA"},
+ {0x180c, "fr_MC"},
+ {0x340c, "fr_ML"},
+ {0x200c, "fr_RE"},
+ {0x280c, "fr_SN"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0462, fy, fy_NL)
+
+/* This LCID is really two different locales.*/
+static const ILcidPosixElement ga[] = {
+ {0x3c, "ga"},
+ {0x3c, "gd"},
+ {0x083c, "ga_IE"}, /* Gaelic (Ireland) */
+ {0x043c, "gd_GB"} /* Gaelic (Scotland) */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0456, gl, gl_ES)
+ILCID_POSIX_ELEMENT_ARRAY(0x0447, gu, gu_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0474, gn, gn_PY)
+ILCID_POSIX_ELEMENT_ARRAY(0x0484, gsw,gsw_FR)
+ILCID_POSIX_ELEMENT_ARRAY(0x0468, ha, ha_NG) /* ha_Latn_NG? */
+ILCID_POSIX_ELEMENT_ARRAY(0x0475, haw,haw_US)
+ILCID_POSIX_ELEMENT_ARRAY(0x040d, he, he_IL)
+ILCID_POSIX_ELEMENT_ARRAY(0x0439, hi, hi_IN)
+
+/* This LCID is really four different locales.*/
+static const ILcidPosixElement hr[] = {
+ {0x1a, "hr"},
+ {0x141a, "bs_Latn_BA"}, /* Bosnian, Bosnia and Herzegovina */
+ {0x141a, "bs_Latn"}, /* Bosnian, Bosnia and Herzegovina */
+ {0x141a, "bs_BA"}, /* Bosnian, Bosnia and Herzegovina */
+ {0x141a, "bs"}, /* Bosnian */
+ {0x201a, "bs_Cyrl_BA"}, /* Bosnian, Bosnia and Herzegovina */
+ {0x201a, "bs_Cyrl"}, /* Bosnian, Bosnia and Herzegovina */
+ {0x101a, "hr_BA"}, /* Croatian in Bosnia */
+ {0x041a, "hr_HR"}, /* Croatian*/
+ {0x181a, "sr_Latn_BA"}, /* Serbo-Croatian in Bosnia */
+ {0x081a, "sr_Latn_CS"}, /* Serbo-Croatian*/
+ {0x081a, "sr_Latn"}, /* It's 0x1a or 0x081a, pick one to make the test program happy. */
+ {0x1c1a, "sr_Cyrl_BA"}, /* Serbo-Croatian in Bosnia */
+ {0x0c1a, "sr_Cyrl_CS"}, /* Serbian*/
+ {0x0c1a, "sr_Cyrl"}, /* It's 0x1a or 0x0c1a, pick one to make the test program happy. */
+ {0x0c1a, "sr"} /* In CLDR sr is sr_Cyrl. */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x040e, hu, hu_HU)
+ILCID_POSIX_ELEMENT_ARRAY(0x042b, hy, hy_AM)
+ILCID_POSIX_ELEMENT_ARRAY(0x0421, id, id_ID)
+ILCID_POSIX_ELEMENT_ARRAY(0x0470, ig, ig_NG)
+ILCID_POSIX_ELEMENT_ARRAY(0x0478, ii, ii_CN)
+ILCID_POSIX_ELEMENT_ARRAY(0x040f, is, is_IS)
+
+static const ILcidPosixElement it[] = {
+ {0x10, "it"},
+ {0x0810, "it_CH"},
+ {0x0410, "it_IT"}
+};
+
+static const ILcidPosixElement iu[] = {
+ {0x5d, "iu"},
+ {0x045d, "iu_Cans_CA"},
+ {0x045d, "iu_Cans"},
+ {0x085d, "iu_Latn_CA"},
+ {0x085d, "iu_Latn"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x040d, iw, iw_IL) /*Left in for compatibility*/
+ILCID_POSIX_ELEMENT_ARRAY(0x0411, ja, ja_JP)
+ILCID_POSIX_ELEMENT_ARRAY(0x0437, ka, ka_GE)
+ILCID_POSIX_ELEMENT_ARRAY(0x043f, kk, kk_KZ)
+ILCID_POSIX_ELEMENT_ARRAY(0x046f, kl, kl_GL)
+ILCID_POSIX_ELEMENT_ARRAY(0x0453, km, km_KH)
+ILCID_POSIX_ELEMENT_ARRAY(0x044b, kn, kn_IN)
+
+static const ILcidPosixElement ko[] = {
+ {0x12, "ko"},
+ {0x0812, "ko_KP"},
+ {0x0412, "ko_KR"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0457, kok, kok_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0471, kr, kr_NG)
+
+static const ILcidPosixElement ks[] = { /* We could add PK and CN too */
+ {0x60, "ks"},
+ {0x0860, "ks_IN"}, /* Documentation doesn't mention script */
+ {0x0460, "ks_Arab_IN"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0440, ky, ky_KG) /* Kyrgyz is spoken in Kyrgyzstan */
+ILCID_POSIX_ELEMENT_ARRAY(0x0476, la, la_IT) /* TODO: Verify the country */
+ILCID_POSIX_ELEMENT_ARRAY(0x046e, lb, lb_LU)
+ILCID_POSIX_ELEMENT_ARRAY(0x0454, lo, lo_LA)
+ILCID_POSIX_ELEMENT_ARRAY(0x0427, lt, lt_LT)
+ILCID_POSIX_ELEMENT_ARRAY(0x0426, lv, lv_LV)
+ILCID_POSIX_ELEMENT_ARRAY(0x0481, mi, mi_NZ)
+ILCID_POSIX_ELEMENT_ARRAY(0x042f, mk, mk_MK)
+ILCID_POSIX_ELEMENT_ARRAY(0x044c, ml, ml_IN)
+
+static const ILcidPosixElement mn[] = {
+ {0x50, "mn"},
+ {0x0850, "mn_CN"},
+ {0x0450, "mn_MN"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0458, mni,mni_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x047c, moh,moh_CA)
+ILCID_POSIX_ELEMENT_ARRAY(0x044e, mr, mr_IN)
+
+static const ILcidPosixElement ms[] = {
+ {0x3e, "ms"},
+ {0x083e, "ms_BN"}, /* Brunei Darussalam*/
+ {0x043e, "ms_MY"} /* Malaysia*/
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x043a, mt, mt_MT)
+ILCID_POSIX_ELEMENT_ARRAY(0x0455, my, my_MM)
+
+static const ILcidPosixElement ne[] = {
+ {0x61, "ne"},
+ {0x0861, "ne_IN"}, /* India*/
+ {0x0461, "ne_NP"} /* Nepal*/
+};
+
+static const ILcidPosixElement nl[] = {
+ {0x13, "nl"},
+ {0x0813, "nl_BE"},
+ {0x0413, "nl_NL"}
+};
+
+/* The "no" locale split into nb and nn. By default in ICU, "no" is nb.*/
+static const ILcidPosixElement no[] = {
+ {0x14, "nb"}, /* really nb */
+ {0x0414, "nb_NO"}, /* really nb_NO. Keep first in the 414 list. */
+ {0x0414, "no"}, /* really nb_NO */
+ {0x0414, "no_NO"}, /* really nb_NO */
+ {0x0814, "nn_NO"}, /* really nn_NO. Keep first in the 814 list. */
+ {0x0814, "nn"}, /* It's 0x14 or 0x814, pick one to make the test program happy. */
+ {0x0814, "no_NO_NY"}/* really nn_NO */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x046c, nso,nso_ZA) /* TODO: Verify the ISO-639 code */
+ILCID_POSIX_ELEMENT_ARRAY(0x0482, oc, oc_FR)
+ILCID_POSIX_ELEMENT_ARRAY(0x0472, om, om_ET) /* TODO: Verify the country */
+
+/* Declared as or_IN to get around compiler errors*/
+static const ILcidPosixElement or_IN[] = {
+ {0x48, "or"},
+ {0x0448, "or_IN"},
+};
+
+static const ILcidPosixElement pa[] = {
+ {0x46, "pa"},
+ {0x0446, "pa_IN"},
+ {0x0846, "pa_PK"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0415, pl, pl_PL)
+ILCID_POSIX_ELEMENT_ARRAY(0x0463, ps, ps_AF)
+
+static const ILcidPosixElement pt[] = {
+ {0x16, "pt"},
+ {0x0416, "pt_BR"},
+ {0x0816, "pt_PT"}
+};
+
+static const ILcidPosixElement qu[] = {
+ {0x6b, "qu"},
+ {0x046b, "qu_BO"},
+ {0x086b, "qu_EC"},
+ {0x0C6b, "qu_PE"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0486, qut, qut_GT) /* qut is an ISO-639-3 code */
+ILCID_POSIX_ELEMENT_ARRAY(0x0417, rm, rm_CH)
+ILCID_POSIX_ELEMENT_ARRAY(0x0418, ro, ro_RO)
+
+static const ILcidPosixElement root[] = {
+ {0x00, "root"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0419, ru, ru_RU)
+ILCID_POSIX_ELEMENT_ARRAY(0x0487, rw, rw_RW)
+ILCID_POSIX_ELEMENT_ARRAY(0x044f, sa, sa_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0485, sah,sah_RU)
+
+static const ILcidPosixElement sd[] = {
+ {0x59, "sd"},
+ {0x0459, "sd_IN"},
+ {0x0859, "sd_PK"}
+};
+
+static const ILcidPosixElement se[] = {
+ {0x3b, "se"},
+ {0x0c3b, "se_FI"},
+ {0x043b, "se_NO"},
+ {0x083b, "se_SE"},
+ {0x183b, "sma_NO"},
+ {0x1c3b, "sma_SE"},
+ {0x103b, "smj_NO"},
+ {0x143b, "smj_SE"},
+ {0x243b, "smn_FI"},
+ {0x203b, "sms_FI"},
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x045b, si, si_LK)
+ILCID_POSIX_ELEMENT_ARRAY(0x041b, sk, sk_SK)
+ILCID_POSIX_ELEMENT_ARRAY(0x0424, sl, sl_SI)
+ILCID_POSIX_ELEMENT_ARRAY(0x0477, so, so_ET) /* TODO: Verify the country */
+ILCID_POSIX_ELEMENT_ARRAY(0x041c, sq, sq_AL)
+
+static const ILcidPosixElement sv[] = {
+ {0x1d, "sv"},
+ {0x081d, "sv_FI"},
+ {0x041d, "sv_SE"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0441, sw, sw_KE)
+ILCID_POSIX_ELEMENT_ARRAY(0x045A, syr, syr_SY)
+ILCID_POSIX_ELEMENT_ARRAY(0x0449, ta, ta_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x044a, te, te_IN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0428, tg, tg_TJ) /* Cyrillic based by default */
+ILCID_POSIX_ELEMENT_ARRAY(0x041e, th, th_TH)
+
+static const ILcidPosixElement ti[] = {
+ {0x73, "ti"},
+ {0x0873, "ti_ER"},
+ {0x0473, "ti_ET"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0442, tk, tk_TM)
+ILCID_POSIX_ELEMENT_ARRAY(0x0432, tn, tn_BW)
+ILCID_POSIX_ELEMENT_ARRAY(0x041f, tr, tr_TR)
+ILCID_POSIX_ELEMENT_ARRAY(0x0444, tt, tt_RU)
+ILCID_POSIX_ELEMENT_ARRAY(0x0480, ug, ug_CN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0422, uk, uk_UA)
+
+static const ILcidPosixElement ur[] = {
+ {0x20, "ur"},
+ {0x0820, "ur_IN"},
+ {0x0420, "ur_PK"}
+};
+
+static const ILcidPosixElement uz[] = {
+ {0x43, "uz"},
+ {0x0843, "uz_Cyrl_UZ"}, /* Cyrillic based */
+ {0x0843, "uz_Cyrl"}, /* Cyrillic based */
+ {0x0843, "uz_UZ"}, /* Cyrillic based */
+ {0x0443, "uz_Latn_UZ"}, /* Latin based */
+ {0x0443, "uz_Latn"} /* Latin based */
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0433, ve, ve_ZA) /* TODO: Verify the country */
+ILCID_POSIX_ELEMENT_ARRAY(0x042a, vi, vi_VN)
+
+static const ILcidPosixElement wen[] = {
+ {0x2E, "wen"},
+ {0x042E, "wen_DE"},
+ {0x042E, "hsb_DE"},
+ {0x082E, "dsb_DE"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0488, wo, wo_SN)
+ILCID_POSIX_ELEMENT_ARRAY(0x0434, xh, xh_ZA)
+ILCID_POSIX_ELEMENT_ARRAY(0x046a, yo, yo_NG)
+
+static const ILcidPosixElement zh[] = {
+ {0x04, "zh"},
+ {0x0804, "zh_Hans_CN"},
+ {0x0804, "zh_Hans"},
+ {0x0804, "zh_CN"},
+ {0x0c04, "zh_Hant_HK"},
+ {0x0c04, "zh_HK"},
+ {0x1404, "zh_Hant_MO"},
+ {0x1404, "zh_MO"},
+ {0x1004, "zh_Hans_SG"},
+ {0x1004, "zh_SG"},
+ {0x0404, "zh_Hant_TW"},
+ {0x0404, "zh_Hant"},
+ {0x0404, "zh_TW"},
+ {0x30404,"zh_Hant_TW"}, /* Bopomofo order */
+ {0x30404,"zh_TW"}, /* Bopomofo order */
+ {0x20404,"zh_Hant_TW@collation=stroke"},
+ {0x20404,"zh_TW@collation=stroke"},
+ {0x20804,"zh_Hans_CN@collation=stroke"},
+ {0x20804,"zh_CN@collation=stroke"}
+};
+
+ILCID_POSIX_ELEMENT_ARRAY(0x0435, zu, zu_ZA)
+
+/* This must be static and grouped by LCID. */
+
+/* non-existent ISO-639-2 codes */
+/*
+0x466 Edo
+0x467 Fulfulde - Nigeria
+0x486 K'iche - Guatemala
+0x430 Sutu
+*/
+static const ILcidPosixMap gPosixIDmap[] = {
+ ILCID_POSIX_MAP(af), /* af Afrikaans 0x36 */
+ ILCID_POSIX_MAP(am), /* am Amharic 0x5e */
+ ILCID_POSIX_MAP(ar), /* ar Arabic 0x01 */
+ ILCID_POSIX_MAP(arn), /* arn Araucanian/Mapudungun 0x7a */
+ ILCID_POSIX_MAP(as), /* as Assamese 0x4d */
+ ILCID_POSIX_MAP(az), /* az Azerbaijani 0x2c */
+ ILCID_POSIX_MAP(ba), /* ba Bashkir 0x6d */
+ ILCID_POSIX_MAP(be), /* be Belarusian 0x23 */
+ ILCID_POSIX_MAP(ber), /* ber Berber/Tamazight 0x5f */
+ ILCID_POSIX_MAP(bg), /* bg Bulgarian 0x02 */
+ ILCID_POSIX_MAP(bn), /* bn Bengali; Bangla 0x45 */
+ ILCID_POSIX_MAP(bo), /* bo Tibetan 0x51 */
+ ILCID_POSIX_MAP(br), /* br Breton 0x7e */
+ ILCID_POSIX_MAP(ca), /* ca Catalan 0x03 */
+ ILCID_POSIX_MAP(chr), /* chr Cherokee 0x5c */
+ ILCID_POSIX_MAP(co), /* co Corsican 0x83 */
+ ILCID_POSIX_MAP(cs_CZ), /* cs Czech 0x05 */
+ ILCID_POSIX_MAP(cy), /* cy Welsh 0x52 */
+ ILCID_POSIX_MAP(da), /* da Danish 0x06 */
+ ILCID_POSIX_MAP(de), /* de German 0x07 */
+ ILCID_POSIX_MAP(dv), /* dv Divehi 0x65 */
+ ILCID_POSIX_MAP(el), /* el Greek 0x08 */
+ ILCID_POSIX_MAP(en), /* en English 0x09 */
+ ILCID_POSIX_MAP(en_US_POSIX), /* invariant 0x7f */
+ ILCID_POSIX_MAP(es), /* es Spanish 0x0a */
+ ILCID_POSIX_MAP(et), /* et Estonian 0x25 */
+ ILCID_POSIX_MAP(eu), /* eu Basque 0x2d */
+ ILCID_POSIX_MAP(fa), /* fa Persian/Farsi 0x29 */
+ ILCID_POSIX_MAP(fa_AF), /* fa Persian/Dari 0x8c */
+ ILCID_POSIX_MAP(fi), /* fi Finnish 0x0b */
+ ILCID_POSIX_MAP(fil), /* fil Filipino 0x64 */
+ ILCID_POSIX_MAP(fo), /* fo Faroese 0x38 */
+ ILCID_POSIX_MAP(fr), /* fr French 0x0c */
+ ILCID_POSIX_MAP(fy), /* fy Frisian 0x62 */
+ ILCID_POSIX_MAP(ga), /* * Gaelic (Ireland,Scotland) 0x3c */
+ ILCID_POSIX_MAP(gl), /* gl Galician 0x56 */
+ ILCID_POSIX_MAP(gn), /* gn Guarani 0x74 */
+ ILCID_POSIX_MAP(gsw), /* gsw Alemanic/Alsatian/Swiss German 0x84 */
+ ILCID_POSIX_MAP(gu), /* gu Gujarati 0x47 */
+ ILCID_POSIX_MAP(ha), /* ha Hausa 0x68 */
+ ILCID_POSIX_MAP(haw), /* haw Hawaiian 0x75 */
+ ILCID_POSIX_MAP(he), /* he Hebrew (formerly iw) 0x0d */
+ ILCID_POSIX_MAP(hi), /* hi Hindi 0x39 */
+ ILCID_POSIX_MAP(hr), /* * Croatian and others 0x1a */
+ ILCID_POSIX_MAP(hu), /* hu Hungarian 0x0e */
+ ILCID_POSIX_MAP(hy), /* hy Armenian 0x2b */
+ ILCID_POSIX_MAP(id), /* id Indonesian (formerly in) 0x21 */
+ ILCID_POSIX_MAP(ig), /* ig Igbo 0x70 */
+ ILCID_POSIX_MAP(ii), /* ii Sichuan Yi 0x78 */
+ ILCID_POSIX_MAP(is), /* is Icelandic 0x0f */
+ ILCID_POSIX_MAP(it), /* it Italian 0x10 */
+ ILCID_POSIX_MAP(iu), /* iu Inuktitut 0x5d */
+ ILCID_POSIX_MAP(iw), /* iw Hebrew 0x0d */
+ ILCID_POSIX_MAP(ja), /* ja Japanese 0x11 */
+ ILCID_POSIX_MAP(ka), /* ka Georgian 0x37 */
+ ILCID_POSIX_MAP(kk), /* kk Kazakh 0x3f */
+ ILCID_POSIX_MAP(kl), /* kl Kalaallisut 0x6f */
+ ILCID_POSIX_MAP(km), /* km Khmer 0x53 */
+ ILCID_POSIX_MAP(kn), /* kn Kannada 0x4b */
+ ILCID_POSIX_MAP(ko), /* ko Korean 0x12 */
+ ILCID_POSIX_MAP(kok), /* kok Konkani 0x57 */
+ ILCID_POSIX_MAP(kr), /* kr Kanuri 0x71 */
+ ILCID_POSIX_MAP(ks), /* ks Kashmiri 0x60 */
+ ILCID_POSIX_MAP(ky), /* ky Kyrgyz 0x40 */
+ ILCID_POSIX_MAP(lb), /* lb Luxembourgish 0x6e */
+ ILCID_POSIX_MAP(la), /* la Latin 0x76 */
+ ILCID_POSIX_MAP(lo), /* lo Lao 0x54 */
+ ILCID_POSIX_MAP(lt), /* lt Lithuanian 0x27 */
+ ILCID_POSIX_MAP(lv), /* lv Latvian, Lettish 0x26 */
+ ILCID_POSIX_MAP(mi), /* mi Maori 0x81 */
+ ILCID_POSIX_MAP(mk), /* mk Macedonian 0x2f */
+ ILCID_POSIX_MAP(ml), /* ml Malayalam 0x4c */
+ ILCID_POSIX_MAP(mn), /* mn Mongolian 0x50 */
+ ILCID_POSIX_MAP(mni), /* mni Manipuri 0x58 */
+ ILCID_POSIX_MAP(moh), /* moh Mohawk 0x7c */
+ ILCID_POSIX_MAP(mr), /* mr Marathi 0x4e */
+ ILCID_POSIX_MAP(ms), /* ms Malay 0x3e */
+ ILCID_POSIX_MAP(mt), /* mt Maltese 0x3a */
+ ILCID_POSIX_MAP(my), /* my Burmese 0x55 */
+/* ILCID_POSIX_MAP(nb), // no Norwegian 0x14 */
+ ILCID_POSIX_MAP(ne), /* ne Nepali 0x61 */
+ ILCID_POSIX_MAP(nl), /* nl Dutch 0x13 */
+/* ILCID_POSIX_MAP(nn), // no Norwegian 0x14 */
+ ILCID_POSIX_MAP(no), /* * Norwegian 0x14 */
+ ILCID_POSIX_MAP(nso), /* nso Sotho, Northern (Sepedi dialect) 0x6c */
+ ILCID_POSIX_MAP(oc), /* oc Occitan 0x82 */
+ ILCID_POSIX_MAP(om), /* om Oromo 0x72 */
+ ILCID_POSIX_MAP(or_IN), /* or Oriya 0x48 */
+ ILCID_POSIX_MAP(pa), /* pa Punjabi 0x46 */
+ ILCID_POSIX_MAP(pl), /* pl Polish 0x15 */
+ ILCID_POSIX_MAP(ps), /* ps Pashto 0x63 */
+ ILCID_POSIX_MAP(pt), /* pt Portuguese 0x16 */
+ ILCID_POSIX_MAP(qu), /* qu Quechua 0x6B */
+ ILCID_POSIX_MAP(qut), /* qut K'iche 0x86 */
+ ILCID_POSIX_MAP(rm), /* rm Raeto-Romance/Romansh 0x17 */
+ ILCID_POSIX_MAP(ro), /* ro Romanian 0x18 */
+ ILCID_POSIX_MAP(root), /* root 0x00 */
+ ILCID_POSIX_MAP(ru), /* ru Russian 0x19 */
+ ILCID_POSIX_MAP(rw), /* rw Kinyarwanda 0x87 */
+ ILCID_POSIX_MAP(sa), /* sa Sanskrit 0x4f */
+ ILCID_POSIX_MAP(sah), /* sah Yakut 0x85 */
+ ILCID_POSIX_MAP(sd), /* sd Sindhi 0x59 */
+ ILCID_POSIX_MAP(se), /* se Sami 0x3b */
+/* ILCID_POSIX_MAP(sh), // sh Serbo-Croatian 0x1a */
+ ILCID_POSIX_MAP(si), /* si Sinhalese 0x5b */
+ ILCID_POSIX_MAP(sk), /* sk Slovak 0x1b */
+ ILCID_POSIX_MAP(sl), /* sl Slovenian 0x24 */
+ ILCID_POSIX_MAP(so), /* so Somali 0x77 */
+ ILCID_POSIX_MAP(sq), /* sq Albanian 0x1c */
+/* ILCID_POSIX_MAP(sr), // sr Serbian 0x1a */
+ ILCID_POSIX_MAP(sv), /* sv Swedish 0x1d */
+ ILCID_POSIX_MAP(sw), /* sw Swahili 0x41 */
+ ILCID_POSIX_MAP(syr), /* syr Syriac 0x5A */
+ ILCID_POSIX_MAP(ta), /* ta Tamil 0x49 */
+ ILCID_POSIX_MAP(te), /* te Telugu 0x4a */
+ ILCID_POSIX_MAP(tg), /* tg Tajik 0x28 */
+ ILCID_POSIX_MAP(th), /* th Thai 0x1e */
+ ILCID_POSIX_MAP(ti), /* ti Tigrigna 0x73 */
+ ILCID_POSIX_MAP(tk), /* tk Turkmen 0x42 */
+ ILCID_POSIX_MAP(tn), /* tn Tswana 0x32 */
+ ILCID_POSIX_MAP(tr), /* tr Turkish 0x1f */
+ ILCID_POSIX_MAP(tt), /* tt Tatar 0x44 */
+ ILCID_POSIX_MAP(ug), /* ug Uighur 0x80 */
+ ILCID_POSIX_MAP(uk), /* uk Ukrainian 0x22 */
+ ILCID_POSIX_MAP(ur), /* ur Urdu 0x20 */
+ ILCID_POSIX_MAP(uz), /* uz Uzbek 0x43 */
+ ILCID_POSIX_MAP(ve), /* ve Venda 0x33 */
+ ILCID_POSIX_MAP(vi), /* vi Vietnamese 0x2a */
+ ILCID_POSIX_MAP(wen), /* wen Sorbian 0x2e */
+ ILCID_POSIX_MAP(wo), /* wo Wolof 0x88 */
+ ILCID_POSIX_MAP(xh), /* xh Xhosa 0x34 */
+ ILCID_POSIX_MAP(yo), /* yo Yoruba 0x6a */
+ ILCID_POSIX_MAP(zh), /* zh Chinese 0x04 */
+ ILCID_POSIX_MAP(zu), /* zu Zulu 0x35 */
+};
+
+static const uint32_t gLocaleCount = sizeof(gPosixIDmap)/sizeof(ILcidPosixMap);
+
+/**
+ * Do not call this function. It is called by hostID.
+ * The function is not private because this struct must stay as a C struct,
+ * and this is an internal class.
+ */
+static int32_t
+idCmp(const char* id1, const char* id2)
+{
+ int32_t diffIdx = 0;
+ while (*id1 == *id2 && *id1 != 0) {
+ diffIdx++;
+ id1++;
+ id2++;
+ }
+ return diffIdx;
+}
+
+/**
+ * Searches for a Windows LCID
+ *
+ * @param posixid the Posix style locale id.
+ * @param status gets set to U_ILLEGAL_ARGUMENT_ERROR when the Posix ID has
+ * no equivalent Windows LCID.
+ * @return the LCID
+ */
+static uint32_t
+getHostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode* status)
+{
+ int32_t bestIdx = 0;
+ int32_t bestIdxDiff = 0;
+ int32_t posixIDlen = (int32_t)uprv_strlen(posixID);
+ uint32_t idx;
+
+ for (idx = 0; idx < this_0->numRegions; idx++ ) {
+ int32_t sameChars = idCmp(posixID, this_0->regionMaps[idx].posixID);
+ if (sameChars > bestIdxDiff && this_0->regionMaps[idx].posixID[sameChars] == 0) {
+ if (posixIDlen == sameChars) {
+ /* Exact match */
+ return this_0->regionMaps[idx].hostID;
+ }
+ bestIdxDiff = sameChars;
+ bestIdx = idx;
+ }
+ }
+ /* We asked for something unusual, like en_ZZ, and we try to return the number for the same language. */
+ /* We also have to make sure that sid and si and similar string subsets don't match. */
+ if ((posixID[bestIdxDiff] == '_' || posixID[bestIdxDiff] == '@')
+ && this_0->regionMaps[bestIdx].posixID[bestIdxDiff] == 0)
+ {
+ *status = U_USING_FALLBACK_WARNING;
+ return this_0->regionMaps[bestIdx].hostID;
+ }
+
+ /*no match found */
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return this_0->regionMaps->hostID;
+}
+
+static const char*
+getPosixID(const ILcidPosixMap *this_0, uint32_t hostID)
+{
+ uint32_t i;
+ for (i = 0; i <= this_0->numRegions; i++)
+ {
+ if (this_0->regionMaps[i].hostID == hostID)
+ {
+ return this_0->regionMaps[i].posixID;
+ }
+ }
+
+ /* If you get here, then no matching region was found,
+ so return the language id with the wild card region. */
+ return this_0->regionMaps[0].posixID;
+}
+
+/*
+//////////////////////////////////////
+//
+// LCID --> POSIX
+//
+/////////////////////////////////////
+*/
+
+U_CAPI const char *
+uprv_convertToPosix(uint32_t hostid, UErrorCode* status)
+{
+ uint16_t langID = LANGUAGE_LCID(hostid);
+ uint32_t index;
+
+ for (index = 0; index < gLocaleCount; index++)
+ {
+ if (langID == gPosixIDmap[index].regionMaps->hostID)
+ {
+ return getPosixID(&gPosixIDmap[index], hostid);
+ }
+ }
+
+ /* no match found */
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+}
+
+/*
+//////////////////////////////////////
+//
+// POSIX --> LCID
+// This should only be called from uloc_getLCID.
+// The locale ID must be in canonical form.
+// langID is separate so that this file doesn't depend on the uloc_* API.
+//
+/////////////////////////////////////
+*/
+
+U_CAPI uint32_t
+uprv_convertToLCID(const char *langID, const char* posixID, UErrorCode* status)
+{
+
+ uint32_t low = 0;
+ uint32_t high = gLocaleCount;
+ uint32_t mid = high;
+ uint32_t oldmid = 0;
+ int32_t compVal;
+
+ uint32_t value = 0;
+ uint32_t fallbackValue = (uint32_t)-1;
+ UErrorCode myStatus;
+ uint32_t idx;
+
+ /* Check for incomplete id. */
+ if (!langID || !posixID || uprv_strlen(langID) < 2 || uprv_strlen(posixID) < 2) {
+ return 0;
+ }
+
+ /*Binary search for the map entry for normal cases */
+
+ while (high > low) /*binary search*/{
+
+ mid = (high+low) >> 1; /*Finds median*/
+
+ if (mid == oldmid)
+ break;
+
+ compVal = uprv_strcmp(langID, gPosixIDmap[mid].regionMaps->posixID);
+ if (compVal < 0){
+ high = mid;
+ }
+ else if (compVal > 0){
+ low = mid;
+ }
+ else /*we found it*/{
+ return getHostID(&gPosixIDmap[mid], posixID, status);
+ }
+ oldmid = mid;
+ }
+
+ /*
+ * Sometimes we can't do a binary search on posixID because some LCIDs
+ * go to different locales. We hit one of those special cases.
+ */
+ for (idx = 0; idx < gLocaleCount; idx++ ) {
+ myStatus = U_ZERO_ERROR;
+ value = getHostID(&gPosixIDmap[idx], posixID, &myStatus);
+ if (myStatus == U_ZERO_ERROR) {
+ return value;
+ }
+ else if (myStatus == U_USING_FALLBACK_WARNING) {
+ fallbackValue = value;
+ }
+ }
+
+ if (fallbackValue != (uint32_t)-1) {
+ *status = U_USING_FALLBACK_WARNING;
+ return fallbackValue;
+ }
+
+ /* no match found */
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0; /* return international (root) */
+}
+
diff --git a/Build/source/libs/icu/icu-xetex/common/locmap.h b/Build/source/libs/icu/icu-xetex/common/locmap.h
new file mode 100644
index 00000000000..7db06070ec3
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locmap.h
@@ -0,0 +1,37 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1996-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File locmap.h : Locale Mapping Classes
+*
+*
+* Created by: Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+* 3/11/97 aliu Added setId().
+* 4/20/99 Madhu Added T_convertToPosix()
+* 09/18/00 george Removed the memory leaks.
+* 08/23/01 george Convert to C
+*============================================================================
+*/
+
+#ifndef LOCMAP_H
+#define LOCMAP_H
+
+#include "unicode/utypes.h"
+
+#define LANGUAGE_LCID(hostID) (uint16_t)(0x03FF & hostID)
+
+U_CAPI const char *uprv_convertToPosix(uint32_t hostid, UErrorCode* status);
+
+/* Don't call this function directly. Use uloc_getLCID instead. */
+U_CAPI uint32_t uprv_convertToLCID(const char *langID, const char* posixID, UErrorCode* status);
+
+#endif /* LOCMAP_H */
+
diff --git a/Build/source/libs/icu/icu-xetex/common/locutil.cpp b/Build/source/libs/icu/icu-xetex/common/locutil.cpp
new file mode 100644
index 00000000000..e70b61628cf
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locutil.cpp
@@ -0,0 +1,267 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2002-2006, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE || !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/resbund.h"
+#include "cmemory.h"
+#include "ustrfmt.h"
+#include "locutil.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+#include "umutex.h"
+
+// see LocaleUtility::getAvailableLocaleNames
+static U_NAMESPACE_QUALIFIER Hashtable * LocaleUtility_cache = NULL;
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * Release all static memory held by Locale Utility.
+ */
+U_CDECL_BEGIN
+static UBool U_CALLCONV service_cleanup(void) {
+ if (LocaleUtility_cache) {
+ delete LocaleUtility_cache;
+ LocaleUtility_cache = NULL;
+ }
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+UnicodeString&
+LocaleUtility::canonicalLocaleString(const UnicodeString* id, UnicodeString& result)
+{
+ if (id == NULL) {
+ result.setToBogus();
+ } else {
+ // Fix case only (no other changes) up to the first '@' or '.' or
+ // end of string, whichever comes first. In 3.0 I changed this to
+ // stop at first '@' or '.'. It used to run out to the end of
+ // string. My fix makes the tests pass but is probably
+ // structurally incorrect. See below. [alan 3.0]
+
+ // TODO: Doug, you might want to revise this...
+ result = *id;
+ int32_t i = 0;
+ int32_t end = result.indexOf(AT_SIGN_CHAR);
+ int32_t n = result.indexOf(PERIOD_CHAR);
+ if (n >= 0 && n < end) {
+ end = n;
+ }
+ if (end < 0) {
+ end = result.length();
+ }
+ n = result.indexOf(UNDERSCORE_CHAR);
+ if (n < 0) {
+ n = end;
+ }
+ for (; i < n; ++i) {
+ UChar c = result.charAt(i);
+ if (c >= 0x0041 && c <= 0x005a) {
+ c += 0x20;
+ result.setCharAt(i, c);
+ }
+ }
+ for (n = end; i < n; ++i) {
+ UChar c = result.charAt(i);
+ if (c >= 0x0061 && c <= 0x007a) {
+ c -= 0x20;
+ result.setCharAt(i, c);
+ }
+ }
+ }
+ return result;
+
+#if 0
+ // This code does a proper full level 2 canonicalization of id.
+ // It's nasty to go from UChar to char to char to UChar -- but
+ // that's what you have to do to use the uloc_canonicalize
+ // function on UnicodeStrings.
+
+ // I ended up doing the alternate fix (see above) not for
+ // performance reasons, although performance will certainly be
+ // better, but because doing a full level 2 canonicalization
+ // causes some tests to fail. [alan 3.0]
+
+ // TODO: Doug, you might want to revisit this...
+ result.setToBogus();
+ if (id != 0) {
+ int32_t buflen = id->length() + 8; // space for NUL
+ char* buf = (char*) uprv_malloc(buflen);
+ char* canon = (buf == 0) ? 0 : (char*) uprv_malloc(buflen);
+ if (buf != 0 && canon != 0) {
+ U_ASSERT(id->extract(0, INT32_MAX, buf, buflen) < buflen);
+ UErrorCode ec = U_ZERO_ERROR;
+ uloc_canonicalize(buf, canon, buflen, &ec);
+ if (U_SUCCESS(ec)) {
+ result = UnicodeString(canon);
+ }
+ }
+ uprv_free(buf);
+ uprv_free(canon);
+ }
+ return result;
+#endif
+}
+
+Locale&
+LocaleUtility::initLocaleFromName(const UnicodeString& id, Locale& result)
+{
+ enum { BUFLEN = 128 }; // larger than ever needed
+
+ if (id.isBogus() || id.length() >= BUFLEN) {
+ result.setToBogus();
+ } else {
+ /*
+ * We need to convert from a UnicodeString to char * in order to
+ * create a Locale.
+ *
+ * Problem: Locale ID strings may contain '@' which is a variant
+ * character and cannot be handled by invariant-character conversion.
+ *
+ * Hack: Since ICU code can handle locale IDs with multiple encodings
+ * of '@' (at least for EBCDIC; it's not known to be a problem for
+ * ASCII-based systems),
+ * we use regular invariant-character conversion for everything else
+ * and manually convert U+0040 into a compiler-char-constant '@'.
+ * While this compilation-time constant may not match the runtime
+ * encoding of '@', it should be one of the encodings which ICU
+ * recognizes.
+ *
+ * There should be only at most one '@' in a locale ID.
+ */
+ char buffer[BUFLEN];
+ int32_t prev, i;
+ prev = 0;
+ for(;;) {
+ i = id.indexOf((UChar)0x40, prev);
+ if(i < 0) {
+ // no @ between prev and the rest of the string
+ id.extract(prev, INT32_MAX, buffer + prev, BUFLEN - prev, US_INV);
+ break; // done
+ } else {
+ // normal invariant-character conversion for text between @s
+ id.extract(prev, i - prev, buffer + prev, BUFLEN - prev, US_INV);
+ // manually "convert" U+0040 at id[i] into '@' at buffer[i]
+ buffer[i] = '@';
+ prev = i + 1;
+ }
+ }
+ result = Locale::createFromName(buffer);
+ }
+ return result;
+}
+
+UnicodeString&
+LocaleUtility::initNameFromLocale(const Locale& locale, UnicodeString& result)
+{
+ if (locale.isBogus()) {
+ result.setToBogus();
+ } else {
+ result.append(UnicodeString(locale.getName(), -1, US_INV));
+ }
+ return result;
+}
+
+const Hashtable*
+LocaleUtility::getAvailableLocaleNames(const UnicodeString& bundleID)
+{
+ // LocaleUtility_cache is a hash-of-hashes. The top-level keys
+ // are path strings ('bundleID') passed to
+ // ures_openAvailableLocales. The top-level values are
+ // second-level hashes. The second-level keys are result strings
+ // from ures_openAvailableLocales. The second-level values are
+ // garbage ((void*)1 or other random pointer).
+
+ UErrorCode status = U_ZERO_ERROR;
+ Hashtable* cache;
+ umtx_lock(NULL);
+ cache = LocaleUtility_cache;
+ umtx_unlock(NULL);
+
+ if (cache == NULL) {
+ cache = new Hashtable(status);
+ if (cache == NULL || U_FAILURE(status)) {
+ return NULL; // catastrophic failure; e.g. out of memory
+ }
+ cache->setValueDeleter(uhash_deleteHashtable);
+ Hashtable* h; // set this to final LocaleUtility_cache value
+ umtx_lock(NULL);
+ h = LocaleUtility_cache;
+ if (h == NULL) {
+ LocaleUtility_cache = h = cache;
+ cache = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_SERVICE, service_cleanup);
+ }
+ umtx_unlock(NULL);
+ if(cache != NULL) {
+ delete cache;
+ }
+ cache = h;
+ }
+
+ U_ASSERT(cache != NULL);
+
+ Hashtable* htp;
+ umtx_lock(NULL);
+ htp = (Hashtable*) cache->get(bundleID);
+ umtx_unlock(NULL);
+
+ if (htp == NULL) {
+ htp = new Hashtable(status);
+ if (htp && U_SUCCESS(status)) {
+ CharString cbundleID(bundleID);
+ const char* path = (const char*) cbundleID;
+ if (*path == 0) path = NULL; // empty string => NULL
+ UEnumeration *uenum = ures_openAvailableLocales(path, &status);
+ for (;;) {
+ const UChar* id = uenum_unext(uenum, NULL, &status);
+ if (id == NULL) {
+ break;
+ }
+ htp->put(UnicodeString(id), (void*)htp, status);
+ }
+ uenum_close(uenum);
+ if (U_FAILURE(status)) {
+ delete htp;
+ return NULL;
+ }
+ umtx_lock(NULL);
+ cache->put(bundleID, (void*)htp, status);
+ umtx_unlock(NULL);
+ }
+ }
+ return htp;
+}
+
+UBool
+LocaleUtility::isFallbackOf(const UnicodeString& root, const UnicodeString& child)
+{
+ return child.indexOf(root) == 0 &&
+ (child.length() == root.length() ||
+ child.charAt(root.length()) == UNDERSCORE_CHAR);
+}
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/locutil.h b/Build/source/libs/icu/icu-xetex/common/locutil.h
new file mode 100644
index 00000000000..cf64e343d06
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/locutil.h
@@ -0,0 +1,37 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2002-2005, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#ifndef LOCUTIL_H
+#define LOCUTIL_H
+
+#include "unicode/utypes.h"
+#include "hash.h"
+
+#if !UCONFIG_NO_SERVICE || !UCONFIG_NO_TRANSLITERATION
+
+
+U_NAMESPACE_BEGIN
+
+// temporary utility functions, till I know where to find them
+// in header so tests can also access them
+
+class U_COMMON_API LocaleUtility {
+public:
+ static UnicodeString& canonicalLocaleString(const UnicodeString* id, UnicodeString& result);
+ static Locale& initLocaleFromName(const UnicodeString& id, Locale& result);
+ static UnicodeString& initNameFromLocale(const Locale& locale, UnicodeString& result);
+ static const Hashtable* getAvailableLocaleNames(const UnicodeString& bundleID);
+ static UBool isFallbackOf(const UnicodeString& root, const UnicodeString& child);
+};
+
+U_NAMESPACE_END
+
+
+#endif
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/msvcres.h b/Build/source/libs/icu/icu-xetex/common/msvcres.h
new file mode 100644
index 00000000000..cad2fe66c41
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/msvcres.h
@@ -0,0 +1,20 @@
+//{{NO_DEPENDENCIES}}
+// Copyright (c) 2003-2005 International Business Machines
+// Corporation and others. All Rights Reserved.
+//
+// Used by common.rc and other .rc files.
+//Do not edit with Microsoft Developer Studio because it will modify this
+//header the wrong way. This is here to prevent Visual Studio .NET from
+//unnessarily building the resource files when it's not needed.
+//
+
+/*
+These are defined before unicode/uversion.h in order to prevent
+STLPort's broken stddef.h from being used when rc.exe parses this file.
+*/
+#define _STLP_OUTERMOST_HEADER_ID 0
+#define _STLP_WINCE 1
+
+#include "unicode/uversion.h"
+
+#define ICU_WEBSITE "http://ibm.com/software/globalization/icu/"
diff --git a/Build/source/libs/icu/icu-xetex/common/mutex.h b/Build/source/libs/icu/icu-xetex/common/mutex.h
new file mode 100644
index 00000000000..26aefbf86b5
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/mutex.h
@@ -0,0 +1,85 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*/
+//----------------------------------------------------------------------------
+// File: mutex.h
+//
+// Lightweight C++ wrapper for umtx_ C mutex functions
+//
+// Author: Alan Liu 1/31/97
+// History:
+// 06/04/97 helena Updated setImplementation as per feedback from 5/21 drop.
+// 04/07/1999 srl refocused as a thin wrapper
+//
+//----------------------------------------------------------------------------
+#ifndef MUTEX_H
+#define MUTEX_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+//----------------------------------------------------------------------------
+// Code within that accesses shared static or global data should
+// should instantiate a Mutex object while doing so. You should make your own
+// private mutex where possible.
+
+// For example:
+//
+// UMTX myMutex;
+//
+// int InitializeMyMutex()
+// {
+// umtx_init( &myMutex );
+// return 0;
+// }
+//
+// static int initializeMyMutex = InitializeMyMutex();
+//
+// void Function(int arg1, int arg2)
+// {
+// static Object* foo; // Shared read-write object
+// Mutex mutex(&myMutex); // or no args for the global lock
+// foo->Method();
+// // When 'mutex' goes out of scope and gets destroyed here, the lock is released
+// }
+//
+// Note: Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
+// returning a Mutex. This is a common mistake which silently slips through the
+// compiler!!
+//
+
+class U_COMMON_API Mutex : public UMemory {
+public:
+ inline Mutex(UMTX *mutex = NULL);
+ inline ~Mutex();
+
+private:
+ UMTX *fMutex;
+
+ Mutex(const Mutex &other); // forbid copying of this class
+ Mutex &operator=(const Mutex &other); // forbid copying of this class
+};
+
+inline Mutex::Mutex(UMTX *mutex)
+ : fMutex(mutex)
+{
+ umtx_lock(fMutex);
+}
+
+inline Mutex::~Mutex()
+{
+ umtx_unlock(fMutex);
+}
+
+U_NAMESPACE_END
+
+#endif //_MUTEX_
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/normlzr.cpp b/Build/source/libs/icu/icu-xetex/common/normlzr.cpp
new file mode 100644
index 00000000000..909bd30b27c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/normlzr.cpp
@@ -0,0 +1,611 @@
+/*
+ *************************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1996-2005, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+#include "unicode/unistr.h"
+#include "unicode/chariter.h"
+#include "unicode/schriter.h"
+#include "unicode/uchriter.h"
+#include "unicode/uiter.h"
+#include "unicode/normlzr.h"
+#include "cmemory.h"
+#include "unormimp.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Normalizer)
+
+//-------------------------------------------------------------------------
+// Constructors and other boilerplate
+//-------------------------------------------------------------------------
+
+Normalizer::Normalizer(const UnicodeString& str, UNormalizationMode mode) :
+ UObject(), fUMode(mode), fOptions(0),
+ currentIndex(0), nextIndex(0),
+ buffer(), bufferPos(0)
+{
+ init(new StringCharacterIterator(str));
+}
+
+Normalizer::Normalizer(const UChar *str, int32_t length, UNormalizationMode mode) :
+ UObject(), fUMode(mode), fOptions(0),
+ currentIndex(0), nextIndex(0),
+ buffer(), bufferPos(0)
+{
+ init(new UCharCharacterIterator(str, length));
+}
+
+Normalizer::Normalizer(const CharacterIterator& iter, UNormalizationMode mode) :
+ UObject(), fUMode(mode), fOptions(0),
+ currentIndex(0), nextIndex(0),
+ buffer(), bufferPos(0)
+{
+ init(iter.clone());
+}
+
+Normalizer::Normalizer(const Normalizer ©) :
+ UObject(copy), fUMode(copy.fUMode), fOptions(copy.fOptions),
+ currentIndex(copy.currentIndex), nextIndex(copy.nextIndex),
+ buffer(copy.buffer), bufferPos(copy.bufferPos)
+{
+ init(((CharacterIterator *)(copy.text->context))->clone());
+}
+
+static const UChar _NUL=0;
+
+void
+Normalizer::init(CharacterIterator *iter) {
+ UErrorCode errorCode=U_ZERO_ERROR;
+
+ text=(UCharIterator *)uprv_malloc(sizeof(UCharIterator));
+ if(text!=NULL) {
+ if(unorm_haveData(&errorCode)) {
+ uiter_setCharacterIterator(text, iter);
+ } else {
+ delete iter;
+ uiter_setCharacterIterator(text, new UCharCharacterIterator(&_NUL, 0));
+ }
+ } else {
+ delete iter;
+ }
+}
+
+Normalizer::~Normalizer()
+{
+ if(text!=NULL) {
+ delete (CharacterIterator *)text->context;
+ uprv_free(text);
+ }
+}
+
+Normalizer*
+Normalizer::clone() const
+{
+ if(this!=0) {
+ return new Normalizer(*this);
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * Generates a hash code for this iterator.
+ */
+int32_t Normalizer::hashCode() const
+{
+ return ((CharacterIterator *)(text->context))->hashCode() + fUMode + fOptions + buffer.hashCode() + bufferPos + currentIndex + nextIndex;
+}
+
+UBool Normalizer::operator==(const Normalizer& that) const
+{
+ return
+ this==&that ||
+ fUMode==that.fUMode &&
+ fOptions==that.fOptions &&
+ *((CharacterIterator *)(text->context))==*((CharacterIterator *)(that.text->context)) &&
+ buffer==that.buffer &&
+ bufferPos==that.bufferPos &&
+ nextIndex==that.nextIndex;
+}
+
+//-------------------------------------------------------------------------
+// Static utility methods
+//-------------------------------------------------------------------------
+
+void U_EXPORT2
+Normalizer::normalize(const UnicodeString& source,
+ UNormalizationMode mode, int32_t options,
+ UnicodeString& result,
+ UErrorCode &status) {
+ if(source.isBogus() || U_FAILURE(status)) {
+ result.setToBogus();
+ if(U_SUCCESS(status)) {
+ status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ } else {
+ UnicodeString localDest;
+ UnicodeString *dest;
+
+ if(&source!=&result) {
+ dest=&result;
+ } else {
+ // the source and result strings are the same object, use a temporary one
+ dest=&localDest;
+ }
+
+ UChar *buffer=dest->getBuffer(source.length());
+ int32_t length=unorm_internalNormalize(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ mode, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ if(status==U_BUFFER_OVERFLOW_ERROR) {
+ status=U_ZERO_ERROR;
+ buffer=dest->getBuffer(length);
+ length=unorm_internalNormalize(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ mode, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ }
+
+ if(dest==&localDest) {
+ result=*dest;
+ }
+ if(U_FAILURE(status)) {
+ result.setToBogus();
+ }
+ }
+}
+
+void U_EXPORT2
+Normalizer::compose(const UnicodeString& source,
+ UBool compat, int32_t options,
+ UnicodeString& result,
+ UErrorCode &status) {
+ if(source.isBogus() || U_FAILURE(status)) {
+ result.setToBogus();
+ if(U_SUCCESS(status)) {
+ status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ } else {
+ UnicodeString localDest;
+ UnicodeString *dest;
+
+ if(&source!=&result) {
+ dest=&result;
+ } else {
+ // the source and result strings are the same object, use a temporary one
+ dest=&localDest;
+ }
+
+ UChar *buffer=dest->getBuffer(source.length());
+ int32_t length=unorm_compose(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ compat, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ if(status==U_BUFFER_OVERFLOW_ERROR) {
+ status=U_ZERO_ERROR;
+ buffer=dest->getBuffer(length);
+ length=unorm_compose(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ compat, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ }
+
+ if(dest==&localDest) {
+ result=*dest;
+ }
+ if(U_FAILURE(status)) {
+ result.setToBogus();
+ }
+ }
+}
+
+void U_EXPORT2
+Normalizer::decompose(const UnicodeString& source,
+ UBool compat, int32_t options,
+ UnicodeString& result,
+ UErrorCode &status) {
+ if(source.isBogus() || U_FAILURE(status)) {
+ result.setToBogus();
+ if(U_SUCCESS(status)) {
+ status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ } else {
+ UnicodeString localDest;
+ UnicodeString *dest;
+
+ if(&source!=&result) {
+ dest=&result;
+ } else {
+ // the source and result strings are the same object, use a temporary one
+ dest=&localDest;
+ }
+
+ UChar *buffer=dest->getBuffer(source.length());
+ int32_t length=unorm_decompose(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ compat, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ if(status==U_BUFFER_OVERFLOW_ERROR) {
+ status=U_ZERO_ERROR;
+ buffer=dest->getBuffer(length);
+ length=unorm_decompose(buffer, dest->getCapacity(),
+ source.getBuffer(), source.length(),
+ compat, options,
+ &status);
+ dest->releaseBuffer(U_SUCCESS(status) ? length : 0);
+ }
+
+ if(dest==&localDest) {
+ result=*dest;
+ }
+ if(U_FAILURE(status)) {
+ result.setToBogus();
+ }
+ }
+}
+
+UnicodeString & U_EXPORT2
+Normalizer::concatenate(UnicodeString &left, UnicodeString &right,
+ UnicodeString &result,
+ UNormalizationMode mode, int32_t options,
+ UErrorCode &errorCode) {
+ if(left.isBogus() || right.isBogus() || U_FAILURE(errorCode)) {
+ result.setToBogus();
+ if(U_SUCCESS(errorCode)) {
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ } else {
+ UnicodeString localDest;
+ UnicodeString *dest;
+
+ if(&left!=&result && &right!=&result) {
+ dest=&result;
+ } else {
+ // the source and result strings are the same object, use a temporary one
+ dest=&localDest;
+ }
+
+ UChar *buffer=dest->getBuffer(left.length()+right.length());
+ int32_t length=unorm_concatenate(left.getBuffer(), left.length(),
+ right.getBuffer(), right.length(),
+ buffer, dest->getCapacity(),
+ mode, options,
+ &errorCode);
+ dest->releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ errorCode=U_ZERO_ERROR;
+ buffer=dest->getBuffer(length);
+ int32_t length=unorm_concatenate(left.getBuffer(), left.length(),
+ right.getBuffer(), right.length(),
+ buffer, dest->getCapacity(),
+ mode, options,
+ &errorCode);
+ dest->releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ if(dest==&localDest) {
+ result=*dest;
+ }
+ if(U_FAILURE(errorCode)) {
+ result.setToBogus();
+ }
+ }
+ return result;
+}
+
+//-------------------------------------------------------------------------
+// Iteration API
+//-------------------------------------------------------------------------
+
+/**
+ * Return the current character in the normalized text.
+ */
+UChar32 Normalizer::current() {
+ if(bufferPos0 || previousNormalize()) {
+ UChar32 c=buffer.char32At(bufferPos-1);
+ bufferPos-=UTF_CHAR_LENGTH(c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+void Normalizer::reset() {
+ currentIndex=nextIndex=text->move(text, 0, UITER_START);
+ clearBuffer();
+}
+
+void
+Normalizer::setIndexOnly(int32_t index) {
+ currentIndex=nextIndex=text->move(text, index, UITER_ZERO); // validates index
+ clearBuffer();
+}
+
+/**
+ * Return the first character in the normalized text-> This resets
+ * the Normalizer's position to the beginning of the text->
+ */
+UChar32 Normalizer::first() {
+ reset();
+ return next();
+}
+
+/**
+ * Return the last character in the normalized text-> This resets
+ * the Normalizer's position to be just before the
+ * the input text corresponding to that normalized character.
+ */
+UChar32 Normalizer::last() {
+ currentIndex=nextIndex=text->move(text, 0, UITER_LIMIT);
+ clearBuffer();
+ return previous();
+}
+
+/**
+ * Retrieve the current iteration position in the input text that is
+ * being normalized. This method is useful in applications such as
+ * searching, where you need to be able to determine the position in
+ * the input text that corresponds to a given normalized output character.
+ *
+ * Note: This method sets the position in the input, while
+ * {@link #next} and {@link #previous} iterate through characters in the
+ * output. This means that there is not necessarily a one-to-one
+ * correspondence between characters returned by next and
+ * previous and the indices passed to and returned from
+ * setIndex and {@link #getIndex}.
+ *
+ */
+int32_t Normalizer::getIndex() const {
+ if(bufferPos This is the begin index
+ * of the CharacterIterator or the start (i.e. 0) of the String
+ * over which this Normalizer is iterating
+ */
+int32_t Normalizer::startIndex() const {
+ return text->getIndex(text, UITER_START);
+}
+
+/**
+ * Retrieve the index of the end of the input text-> This is the end index
+ * of the CharacterIterator or the length of the String
+ * over which this Normalizer is iterating
+ */
+int32_t Normalizer::endIndex() const {
+ return text->getIndex(text, UITER_LIMIT);
+}
+
+//-------------------------------------------------------------------------
+// Property access methods
+//-------------------------------------------------------------------------
+
+void
+Normalizer::setMode(UNormalizationMode newMode)
+{
+ fUMode = newMode;
+}
+
+UNormalizationMode
+Normalizer::getUMode() const
+{
+ return fUMode;
+}
+
+void
+Normalizer::setOption(int32_t option,
+ UBool value)
+{
+ if (value) {
+ fOptions |= option;
+ } else {
+ fOptions &= (~option);
+ }
+}
+
+UBool
+Normalizer::getOption(int32_t option) const
+{
+ return (fOptions & option) != 0;
+}
+
+/**
+ * Set the input text over which this Normalizer will iterate.
+ * The iteration position is set to the beginning of the input text->
+ */
+void
+Normalizer::setText(const UnicodeString& newText,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ CharacterIterator *newIter = new StringCharacterIterator(newText);
+ if (newIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ delete (CharacterIterator *)(text->context);
+ text->context = newIter;
+ reset();
+}
+
+/**
+ * Set the input text over which this Normalizer will iterate.
+ * The iteration position is set to the beginning of the string.
+ */
+void
+Normalizer::setText(const CharacterIterator& newText,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ CharacterIterator *newIter = newText.clone();
+ if (newIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ delete (CharacterIterator *)(text->context);
+ text->context = newIter;
+ reset();
+}
+
+void
+Normalizer::setText(const UChar* newText,
+ int32_t length,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ CharacterIterator *newIter = new UCharCharacterIterator(newText, length);
+ if (newIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ delete (CharacterIterator *)(text->context);
+ text->context = newIter;
+ reset();
+}
+
+/**
+ * Copies the text under iteration into the UnicodeString referred to by "result".
+ * @param result Receives a copy of the text under iteration.
+ */
+void
+Normalizer::getText(UnicodeString& result)
+{
+ ((CharacterIterator *)(text->context))->getText(result);
+}
+
+//-------------------------------------------------------------------------
+// Private utility methods
+//-------------------------------------------------------------------------
+
+void Normalizer::clearBuffer() {
+ buffer.remove();
+ bufferPos=0;
+}
+
+UBool
+Normalizer::nextNormalize() {
+ UChar *p;
+ int32_t length;
+ UErrorCode errorCode;
+
+ clearBuffer();
+ currentIndex=nextIndex;
+ text->move(text, nextIndex, UITER_ZERO);
+ if(!text->hasNext(text)) {
+ return FALSE;
+ }
+
+ errorCode=U_ZERO_ERROR;
+ p=buffer.getBuffer(-1);
+ length=unorm_next(text, p, buffer.getCapacity(),
+ fUMode, fOptions,
+ TRUE, 0,
+ &errorCode);
+ buffer.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ errorCode=U_ZERO_ERROR;
+ text->move(text, nextIndex, UITER_ZERO);
+ p=buffer.getBuffer(length);
+ length=unorm_next(text, p, buffer.getCapacity(),
+ fUMode, fOptions,
+ TRUE, 0,
+ &errorCode);
+ buffer.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ nextIndex=text->getIndex(text, UITER_CURRENT);
+ return U_SUCCESS(errorCode) && !buffer.isEmpty();
+}
+
+UBool
+Normalizer::previousNormalize() {
+ UChar *p;
+ int32_t length;
+ UErrorCode errorCode;
+
+ clearBuffer();
+ nextIndex=currentIndex;
+ text->move(text, currentIndex, UITER_ZERO);
+ if(!text->hasPrevious(text)) {
+ return FALSE;
+ }
+
+ errorCode=U_ZERO_ERROR;
+ p=buffer.getBuffer(-1);
+ length=unorm_previous(text, p, buffer.getCapacity(),
+ fUMode, fOptions,
+ TRUE, 0,
+ &errorCode);
+ buffer.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
+ errorCode=U_ZERO_ERROR;
+ text->move(text, currentIndex, UITER_ZERO);
+ p=buffer.getBuffer(length);
+ length=unorm_previous(text, p, buffer.getCapacity(),
+ fUMode, fOptions,
+ TRUE, 0,
+ &errorCode);
+ buffer.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
+ }
+
+ bufferPos=buffer.length();
+ currentIndex=text->getIndex(text, UITER_CURRENT);
+ return U_SUCCESS(errorCode) && !buffer.isEmpty();
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_NORMALIZATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/parsepos.cpp b/Build/source/libs/icu/icu-xetex/common/parsepos.cpp
new file mode 100644
index 00000000000..26f88205129
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/parsepos.cpp
@@ -0,0 +1,21 @@
+/*
+**********************************************************************
+* Copyright (C) 2003-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#include "unicode/parsepos.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ParsePosition)
+
+ParsePosition::~ParsePosition() {}
+
+ParsePosition *
+ParsePosition::clone() const {
+ return new ParsePosition(*this);
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/propname.cpp b/Build/source/libs/icu/icu-xetex/common/propname.cpp
new file mode 100644
index 00000000000..55e354044f3
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/propname.cpp
@@ -0,0 +1,758 @@
+/*
+**********************************************************************
+* Copyright (c) 2002-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: October 30 2002
+* Since: ICU 2.4
+**********************************************************************
+*/
+#include "propname.h"
+#include "unicode/uchar.h"
+#include "unicode/udata.h"
+#include "umutex.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "ucln_cmn.h"
+#include "uarrsort.h"
+
+U_CDECL_BEGIN
+
+/**
+ * Get the next non-ignorable ASCII character from a property name
+ * and lowercases it.
+ * @return ((advance count for the name)<<8)|character
+ */
+static inline int32_t
+getASCIIPropertyNameChar(const char *name) {
+ int32_t i;
+ char c;
+
+ /* Ignore delimiters '-', '_', and ASCII White_Space */
+ for(i=0;
+ (c=name[i++])==0x2d || c==0x5f ||
+ c==0x20 || (0x09<=c && c<=0x0d);
+ ) {}
+
+ if(c!=0) {
+ return (i<<8)|(uint8_t)uprv_asciitolower((char)c);
+ } else {
+ return i<<8;
+ }
+}
+
+/**
+ * Get the next non-ignorable EBCDIC character from a property name
+ * and lowercases it.
+ * @return ((advance count for the name)<<8)|character
+ */
+static inline int32_t
+getEBCDICPropertyNameChar(const char *name) {
+ int32_t i;
+ char c;
+
+ /* Ignore delimiters '-', '_', and EBCDIC White_Space */
+ for(i=0;
+ (c=name[i++])==0x60 || c==0x6d ||
+ c==0x40 || c==0x05 || c==0x15 || c==0x25 || c==0x0b || c==0x0c || c==0x0d;
+ ) {}
+
+ if(c!=0) {
+ return (i<<8)|(uint8_t)uprv_ebcdictolower((char)c);
+ } else {
+ return i<<8;
+ }
+}
+
+/**
+ * Unicode property names and property value names are compared "loosely".
+ *
+ * UCD.html 4.0.1 says:
+ * For all property names, property value names, and for property values for
+ * Enumerated, Binary, or Catalog properties, use the following
+ * loose matching rule:
+ *
+ * LM3. Ignore case, whitespace, underscore ('_'), and hyphens.
+ *
+ * This function does just that, for (char *) name strings.
+ * It is almost identical to ucnv_compareNames() but also ignores
+ * C0 White_Space characters (U+0009..U+000d, and U+0085 on EBCDIC).
+ *
+ * @internal
+ */
+
+U_CAPI int32_t U_EXPORT2
+uprv_compareASCIIPropertyNames(const char *name1, const char *name2) {
+ int32_t rc, r1, r2;
+
+ for(;;) {
+ r1=getASCIIPropertyNameChar(name1);
+ r2=getASCIIPropertyNameChar(name2);
+
+ /* If we reach the ends of both strings then they match */
+ if(((r1|r2)&0xff)==0) {
+ return 0;
+ }
+
+ /* Compare the lowercased characters */
+ if(r1!=r2) {
+ rc=(r1&0xff)-(r2&0xff);
+ if(rc!=0) {
+ return rc;
+ }
+ }
+
+ name1+=r1>>8;
+ name2+=r2>>8;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+uprv_compareEBCDICPropertyNames(const char *name1, const char *name2) {
+ int32_t rc, r1, r2;
+
+ for(;;) {
+ r1=getEBCDICPropertyNameChar(name1);
+ r2=getEBCDICPropertyNameChar(name2);
+
+ /* If we reach the ends of both strings then they match */
+ if(((r1|r2)&0xff)==0) {
+ return 0;
+ }
+
+ /* Compare the lowercased characters */
+ if(r1!=r2) {
+ rc=(r1&0xff)-(r2&0xff);
+ if(rc!=0) {
+ return rc;
+ }
+ }
+
+ name1+=r1>>8;
+ name2+=r2>>8;
+ }
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+//----------------------------------------------------------------------
+// PropertyAliases implementation
+
+const char*
+PropertyAliases::chooseNameInGroup(Offset offset,
+ UPropertyNameChoice choice) const {
+ int32_t c = choice;
+ if (!offset || c < 0) {
+ return NULL;
+ }
+ const Offset* p = (const Offset*) getPointer(offset);
+ while (c-- > 0) {
+ if (*p++ < 0) return NULL;
+ }
+ Offset a = *p;
+ if (a < 0) a = -a;
+ return (const char*) getPointerNull(a);
+}
+
+const ValueMap*
+PropertyAliases::getValueMap(EnumValue prop) const {
+ NonContiguousEnumToOffset* e2o = (NonContiguousEnumToOffset*) getPointer(enumToValue_offset);
+ Offset a = e2o->getOffset(prop);
+ return (const ValueMap*) (a ? getPointerNull(a) : NULL);
+}
+
+inline const char*
+PropertyAliases::getPropertyName(EnumValue prop,
+ UPropertyNameChoice choice) const {
+ NonContiguousEnumToOffset* e2n = (NonContiguousEnumToOffset*) getPointer(enumToName_offset);
+ return chooseNameInGroup(e2n->getOffset(prop), choice);
+}
+
+inline EnumValue
+PropertyAliases::getPropertyEnum(const char* alias) const {
+ NameToEnum* n2e = (NameToEnum*) getPointer(nameToEnum_offset);
+ return n2e->getEnum(alias, *this);
+}
+
+inline const char*
+PropertyAliases::getPropertyValueName(EnumValue prop,
+ EnumValue value,
+ UPropertyNameChoice choice) const {
+ const ValueMap* vm = getValueMap(prop);
+ if (!vm) return NULL;
+ Offset a;
+ if (vm->enumToName_offset) {
+ a = ((EnumToOffset*) getPointer(vm->enumToName_offset))->
+ getOffset(value);
+ } else {
+ a = ((NonContiguousEnumToOffset*) getPointer(vm->ncEnumToName_offset))->
+ getOffset(value);
+ }
+ return chooseNameInGroup(a, choice);
+}
+
+inline EnumValue
+PropertyAliases::getPropertyValueEnum(EnumValue prop,
+ const char* alias) const {
+ const ValueMap* vm = getValueMap(prop);
+ if (!vm) return UCHAR_INVALID_CODE;
+ NameToEnum* n2e = (NameToEnum*) getPointer(vm->nameToEnum_offset);
+ return n2e->getEnum(alias, *this);
+}
+
+U_NAMESPACE_END
+U_NAMESPACE_USE
+
+//----------------------------------------------------------------------
+// UDataMemory structures
+
+static const PropertyAliases* PNAME = NULL;
+static UDataMemory* UDATA = NULL;
+
+//----------------------------------------------------------------------
+// UDataMemory loading/unloading
+
+/**
+ * udata callback to verify the zone data.
+ */
+U_CDECL_BEGIN
+static UBool U_CALLCONV
+isPNameAcceptable(void* /*context*/,
+ const char* /*type*/, const char* /*name*/,
+ const UDataInfo* info) {
+ return
+ info->size >= sizeof(UDataInfo) &&
+ info->isBigEndian == U_IS_BIG_ENDIAN &&
+ info->charsetFamily == U_CHARSET_FAMILY &&
+ info->dataFormat[0] == PNAME_SIG_0 &&
+ info->dataFormat[1] == PNAME_SIG_1 &&
+ info->dataFormat[2] == PNAME_SIG_2 &&
+ info->dataFormat[3] == PNAME_SIG_3 &&
+ info->formatVersion[0] == PNAME_FORMAT_VERSION;
+}
+
+static UBool U_CALLCONV pname_cleanup(void) {
+ if (UDATA) {
+ udata_close(UDATA);
+ UDATA = NULL;
+ }
+ PNAME = NULL;
+ return TRUE;
+}
+U_CDECL_END
+
+/**
+ * Load the property names data. Caller should check that data is
+ * not loaded BEFORE calling this function. Returns TRUE if the load
+ * succeeds.
+ */
+static UBool _load() {
+ UErrorCode ec = U_ZERO_ERROR;
+ UDataMemory* data =
+ udata_openChoice(0, PNAME_DATA_TYPE, PNAME_DATA_NAME,
+ isPNameAcceptable, 0, &ec);
+ if (U_SUCCESS(ec)) {
+ umtx_lock(NULL);
+ if (UDATA == NULL) {
+ UDATA = data;
+ PNAME = (const PropertyAliases*) udata_getMemory(UDATA);
+ ucln_common_registerCleanup(UCLN_COMMON_PNAME, pname_cleanup);
+ data = NULL;
+ }
+ umtx_unlock(NULL);
+ }
+ if (data) {
+ udata_close(data);
+ }
+ return PNAME!=NULL;
+}
+
+/**
+ * Inline function that expands to code that does a lazy load of the
+ * property names data. If the data is already loaded, avoids an
+ * unnecessary function call. If the data is not loaded, call _load()
+ * to load it, and return TRUE if the load succeeds.
+ */
+static inline UBool load() {
+ UBool f;
+ UMTX_CHECK(NULL, (PNAME!=NULL), f);
+ return f || _load();
+}
+
+//----------------------------------------------------------------------
+// Public API implementation
+
+// The C API is just a thin wrapper. Each function obtains a pointer
+// to the singleton PropertyAliases, and calls the appropriate method
+// on it. If it cannot obtain a pointer, because valid data is not
+// available, then it returns NULL or UCHAR_INVALID_CODE.
+
+U_CAPI const char* U_EXPORT2
+u_getPropertyName(UProperty property,
+ UPropertyNameChoice nameChoice) {
+ return load() ? PNAME->getPropertyName(property, nameChoice)
+ : NULL;
+}
+
+U_CAPI UProperty U_EXPORT2
+u_getPropertyEnum(const char* alias) {
+ UProperty p = load() ? (UProperty) PNAME->getPropertyEnum(alias)
+ : UCHAR_INVALID_CODE;
+ return p;
+}
+
+U_CAPI const char* U_EXPORT2
+u_getPropertyValueName(UProperty property,
+ int32_t value,
+ UPropertyNameChoice nameChoice) {
+ return load() ? PNAME->getPropertyValueName(property, value, nameChoice)
+ : NULL;
+}
+
+U_CAPI int32_t U_EXPORT2
+u_getPropertyValueEnum(UProperty property,
+ const char* alias) {
+ return load() ? PNAME->getPropertyValueEnum(property, alias)
+ : (int32_t)UCHAR_INVALID_CODE;
+}
+
+/* data swapping ------------------------------------------------------------ */
+
+/*
+ * Sub-structure-swappers use the temp array (which is as large as the
+ * actual data) for intermediate storage,
+ * as well as to indicate if a particular structure has been swapped already.
+ * The temp array is initially reset to all 0.
+ * pos is the byte offset of the sub-structure in the inBytes/outBytes/temp arrays.
+ */
+
+int32_t
+EnumToOffset::swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode) {
+ const EnumToOffset *inMap;
+ EnumToOffset *outMap, *tempMap;
+ int32_t size;
+
+ tempMap=(EnumToOffset *)(temp+pos);
+ if(tempMap->enumStart!=0 || tempMap->enumLimit!=0) {
+ /* this map was swapped already */
+ size=tempMap->getSize();
+ return size;
+ }
+
+ inMap=(const EnumToOffset *)(inBytes+pos);
+ outMap=(EnumToOffset *)(outBytes+pos);
+
+ tempMap->enumStart=udata_readInt32(ds, inMap->enumStart);
+ tempMap->enumLimit=udata_readInt32(ds, inMap->enumLimit);
+ size=tempMap->getSize();
+
+ if(length>=0) {
+ if(length<(pos+size)) {
+ if(length<(int32_t)sizeof(PropertyAliases)) {
+ udata_printError(ds, "upname_swap(EnumToOffset): too few bytes (%d after header)\n"
+ " for pnames.icu EnumToOffset{%d..%d} at %d\n",
+ length, tempMap->enumStart, tempMap->enumLimit, pos);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ }
+
+ /* swap enumStart and enumLimit */
+ ds->swapArray32(ds, inMap, 2*sizeof(EnumValue), outMap, pErrorCode);
+
+ /* swap _offsetArray[] */
+ ds->swapArray16(ds, inMap->getOffsetArray(), (tempMap->enumLimit-tempMap->enumStart)*sizeof(Offset),
+ outMap->getOffsetArray(), pErrorCode);
+ }
+
+ return size;
+}
+
+int32_t
+NonContiguousEnumToOffset::swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode) {
+ const NonContiguousEnumToOffset *inMap;
+ NonContiguousEnumToOffset *outMap, *tempMap;
+ int32_t size;
+
+ tempMap=(NonContiguousEnumToOffset *)(temp+pos);
+ if(tempMap->count!=0) {
+ /* this map was swapped already */
+ size=tempMap->getSize();
+ return size;
+ }
+
+ inMap=(const NonContiguousEnumToOffset *)(inBytes+pos);
+ outMap=(NonContiguousEnumToOffset *)(outBytes+pos);
+
+ tempMap->count=udata_readInt32(ds, inMap->count);
+ size=tempMap->getSize();
+
+ if(length>=0) {
+ if(length<(pos+size)) {
+ if(length<(int32_t)sizeof(PropertyAliases)) {
+ udata_printError(ds, "upname_swap(NonContiguousEnumToOffset): too few bytes (%d after header)\n"
+ " for pnames.icu NonContiguousEnumToOffset[%d] at %d\n",
+ length, tempMap->count, pos);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ }
+
+ /* swap count and _enumArray[] */
+ length=(1+tempMap->count)*sizeof(EnumValue);
+ ds->swapArray32(ds, inMap, length,
+ outMap, pErrorCode);
+
+ /* swap _offsetArray[] */
+ pos+=length;
+ ds->swapArray16(ds, inBytes+pos, tempMap->count*sizeof(Offset),
+ outBytes+pos, pErrorCode);
+ }
+
+ return size;
+}
+
+struct NameAndIndex {
+ Offset name, index;
+};
+
+U_CDECL_BEGIN
+typedef int32_t U_CALLCONV PropNameCompareFn(const char *name1, const char *name2);
+
+struct CompareContext {
+ const char *chars;
+ PropNameCompareFn *propCompare;
+};
+
+static int32_t U_CALLCONV
+upname_compareRows(const void *context, const void *left, const void *right) {
+ CompareContext *cmp=(CompareContext *)context;
+ return cmp->propCompare(cmp->chars+((const NameAndIndex *)left)->name,
+ cmp->chars+((const NameAndIndex *)right)->name);
+}
+U_CDECL_END
+
+int32_t
+NameToEnum::swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode) {
+ const NameToEnum *inMap;
+ NameToEnum *outMap, *tempMap;
+
+ const EnumValue *inEnumArray;
+ EnumValue *outEnumArray;
+
+ const Offset *inNameArray;
+ Offset *outNameArray;
+
+ NameAndIndex *sortArray;
+ CompareContext cmp;
+
+ int32_t i, size, oldIndex;
+
+ tempMap=(NameToEnum *)(temp+pos);
+ if(tempMap->count!=0) {
+ /* this map was swapped already */
+ size=tempMap->getSize();
+ return size;
+ }
+
+ inMap=(const NameToEnum *)(inBytes+pos);
+ outMap=(NameToEnum *)(outBytes+pos);
+
+ tempMap->count=udata_readInt32(ds, inMap->count);
+ size=tempMap->getSize();
+
+ if(length>=0) {
+ if(length<(pos+size)) {
+ if(length<(int32_t)sizeof(PropertyAliases)) {
+ udata_printError(ds, "upname_swap(NameToEnum): too few bytes (%d after header)\n"
+ " for pnames.icu NameToEnum[%d] at %d\n",
+ length, tempMap->count, pos);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ }
+
+ /* swap count */
+ ds->swapArray32(ds, inMap, 4, outMap, pErrorCode);
+
+ inEnumArray=inMap->getEnumArray();
+ outEnumArray=outMap->getEnumArray();
+
+ inNameArray=(const Offset *)(inEnumArray+tempMap->count);
+ outNameArray=(Offset *)(outEnumArray+tempMap->count);
+
+ if(ds->inCharset==ds->outCharset) {
+ /* no need to sort, just swap the enum/name arrays */
+ ds->swapArray32(ds, inEnumArray, tempMap->count*4, outEnumArray, pErrorCode);
+ ds->swapArray16(ds, inNameArray, tempMap->count*2, outNameArray, pErrorCode);
+ return size;
+ }
+
+ /*
+ * The name and enum arrays are sorted by names and must be resorted
+ * if inCharset!=outCharset.
+ * We use the corresponding part of the temp array to sort an array
+ * of pairs of name offsets and sorting indexes.
+ * Then the sorting indexes are used to permutate-swap the name and enum arrays.
+ *
+ * The outBytes must already contain the swapped strings.
+ */
+ sortArray=(NameAndIndex *)tempMap->getEnumArray();
+ for(i=0; icount; ++i) {
+ sortArray[i].name=udata_readInt16(ds, inNameArray[i]);
+ sortArray[i].index=(Offset)i;
+ }
+
+ /*
+ * use a stable sort to avoid shuffling of equal strings,
+ * which makes testing harder
+ */
+ cmp.chars=(const char *)outBytes;
+ if (ds->outCharset==U_ASCII_FAMILY) {
+ cmp.propCompare=uprv_compareASCIIPropertyNames;
+ }
+ else {
+ cmp.propCompare=uprv_compareEBCDICPropertyNames;
+ }
+ uprv_sortArray(sortArray, tempMap->count, sizeof(NameAndIndex),
+ upname_compareRows, &cmp,
+ TRUE, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ udata_printError(ds, "upname_swap(NameToEnum).uprv_sortArray(%d items) failed\n",
+ tempMap->count);
+ return 0;
+ }
+
+ /* copy/swap/permutate _enumArray[] and _nameArray[] */
+ if(inEnumArray!=outEnumArray) {
+ for(i=0; icount; ++i) {
+ oldIndex=sortArray[i].index;
+ ds->swapArray32(ds, inEnumArray+oldIndex, 4, outEnumArray+i, pErrorCode);
+ ds->swapArray16(ds, inNameArray+oldIndex, 2, outNameArray+i, pErrorCode);
+ }
+ } else {
+ /*
+ * in-place swapping: need to permutate into a temporary array
+ * and then copy back to not destroy the data
+ */
+ EnumValue *tempEnumArray;
+ Offset *oldIndexes;
+
+ /* write name offsets directly from sortArray */
+ for(i=0; icount; ++i) {
+ ds->writeUInt16((uint16_t *)outNameArray+i, (uint16_t)sortArray[i].name);
+ }
+
+ /*
+ * compress the oldIndexes into a separate array to make space for tempEnumArray
+ * the tempMap _nameArray becomes oldIndexes[], getting the index
+ * values from the 2D sortArray[],
+ * while sortArray=tempMap _enumArray[] becomes tempEnumArray[]
+ * this saves us allocating more memory
+ *
+ * it works because sizeof(NameAndIndex)<=sizeof(EnumValue)
+ * and because the nameArray[] can be used for oldIndexes[]
+ */
+ tempEnumArray=(EnumValue *)sortArray;
+ oldIndexes=(Offset *)(sortArray+tempMap->count);
+
+ /* copy sortArray[].index values into oldIndexes[] */
+ for(i=0; icount; ++i) {
+ oldIndexes[i]=sortArray[i].index;
+ }
+
+ /* permutate inEnumArray[] into tempEnumArray[] */
+ for(i=0; icount; ++i) {
+ ds->swapArray32(ds, inEnumArray+oldIndexes[i], 4, tempEnumArray+i, pErrorCode);
+ }
+
+ /* copy tempEnumArray[] to outEnumArray[] */
+ uprv_memcpy(outEnumArray, tempEnumArray, tempMap->count*4);
+ }
+ }
+
+ return size;
+}
+
+int32_t
+PropertyAliases::swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ UErrorCode *pErrorCode) {
+ const PropertyAliases *inAliases;
+ PropertyAliases *outAliases;
+ PropertyAliases aliases;
+
+ const ValueMap *inValueMaps;
+ ValueMap *outValueMaps;
+ ValueMap valueMap;
+
+ uint8_t *temp;
+
+ int32_t i;
+
+ inAliases=(const PropertyAliases *)inBytes;
+ outAliases=(PropertyAliases *)outBytes;
+
+ /* read the input PropertyAliases - all 16-bit values */
+ for(i=0; i<(int32_t)sizeof(PropertyAliases)/2; ++i) {
+ ((uint16_t *)&aliases)[i]=ds->readUInt16(((const uint16_t *)inBytes)[i]);
+ }
+
+ if(length>=0) {
+ if(lengthswapArray16(ds, inAliases, sizeof(PropertyAliases), outAliases, pErrorCode);
+
+ /* swap the name groups */
+ ds->swapArray16(ds, inBytes+aliases.nameGroupPool_offset,
+ aliases.stringPool_offset-aliases.nameGroupPool_offset,
+ outBytes+aliases.nameGroupPool_offset, pErrorCode);
+
+ /* swap the strings */
+ udata_swapInvStringBlock(ds, inBytes+aliases.stringPool_offset,
+ aliases.total_size-aliases.stringPool_offset,
+ outBytes+aliases.stringPool_offset, pErrorCode);
+
+ /*
+ * alloc uint8_t temp[total_size] and reset it
+ * swap each top-level struct, put at least the count fields into temp
+ * use subclass-specific swap() functions
+ * enumerate value maps, for each
+ * if temp does not have count!=0 yet
+ * read count, put it into temp
+ * swap the array(s)
+ * resort strings in name->enum maps
+ * swap value maps
+ */
+ temp=(uint8_t *)uprv_malloc(aliases.total_size);
+ if(temp==NULL) {
+ udata_printError(ds, "upname_swap(): unable to allocate temp memory (%d bytes)\n",
+ aliases.total_size);
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ uprv_memset(temp, 0, aliases.total_size);
+
+ /* swap properties->name groups map */
+ NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
+ temp, aliases.enumToName_offset, pErrorCode);
+
+ /* swap name->properties map */
+ NameToEnum::swap(ds, inBytes, length, outBytes,
+ temp, aliases.nameToEnum_offset, pErrorCode);
+
+ /* swap properties->value maps map */
+ NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
+ temp, aliases.enumToValue_offset, pErrorCode);
+
+ /* enumerate all ValueMaps and swap them */
+ inValueMaps=(const ValueMap *)(inBytes+aliases.valueMap_offset);
+ outValueMaps=(ValueMap *)(outBytes+aliases.valueMap_offset);
+
+ for(i=0; iswapArray16(ds, inValueMaps, aliases.valueMap_count*sizeof(ValueMap),
+ outValueMaps, pErrorCode);
+
+ /* name groups and strings were swapped above */
+
+ /* release temp */
+ uprv_free(temp);
+ }
+
+ return aliases.total_size;
+}
+
+U_CAPI int32_t U_EXPORT2
+upname_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode) {
+ const UDataInfo *pInfo;
+ int32_t headerSize;
+
+ const uint8_t *inBytes;
+ uint8_t *outBytes;
+
+ /* udata_swapDataHeader checks the arguments */
+ headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* check data format and format version */
+ pInfo=(const UDataInfo *)((const char *)inData+4);
+ if(!(
+ pInfo->dataFormat[0]==0x70 && /* dataFormat="pnam" */
+ pInfo->dataFormat[1]==0x6e &&
+ pInfo->dataFormat[2]==0x61 &&
+ pInfo->dataFormat[3]==0x6d &&
+ pInfo->formatVersion[0]==1
+ )) {
+ udata_printError(ds, "upname_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as pnames.icu\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0]);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ inBytes=(const uint8_t *)inData+headerSize;
+ outBytes=(uint8_t *)outData+headerSize;
+
+ if(length>=0) {
+ length-=headerSize;
+ if(length<(int32_t)sizeof(PropertyAliases)) {
+ udata_printError(ds, "upname_swap(): too few bytes (%d after header) for pnames.icu\n",
+ length);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ }
+
+ return headerSize+PropertyAliases::swap(ds, inBytes, length, outBytes, pErrorCode);
+}
+
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/propname.h b/Build/source/libs/icu/icu-xetex/common/propname.h
new file mode 100644
index 00000000000..a3a77181a2b
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/propname.h
@@ -0,0 +1,515 @@
+/*
+**********************************************************************
+* Copyright (c) 2002-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: October 30 2002
+* Since: ICU 2.4
+**********************************************************************
+*/
+#ifndef PROPNAME_H
+#define PROPNAME_H
+
+#include "unicode/utypes.h"
+#include "unicode/uchar.h"
+#include "udataswp.h"
+#include "uprops.h"
+
+/*
+ * This header defines the in-memory layout of the property names data
+ * structure representing the UCD data files PropertyAliases.txt and
+ * PropertyValueAliases.txt. It is used by:
+ * propname.cpp - reads data
+ * genpname - creates data
+ */
+
+/* low-level char * property name comparison -------------------------------- */
+
+U_CDECL_BEGIN
+
+/**
+ * \var uprv_comparePropertyNames
+ * Unicode property names and property value names are compared "loosely".
+ *
+ * UCD.html 4.0.1 says:
+ * For all property names, property value names, and for property values for
+ * Enumerated, Binary, or Catalog properties, use the following
+ * loose matching rule:
+ *
+ * LM3. Ignore case, whitespace, underscore ('_'), and hyphens.
+ *
+ * This function does just that, for (char *) name strings.
+ * It is almost identical to ucnv_compareNames() but also ignores
+ * C0 White_Space characters (U+0009..U+000d, and U+0085 on EBCDIC).
+ *
+ * @internal
+ */
+
+U_CAPI int32_t U_EXPORT2
+uprv_compareASCIIPropertyNames(const char *name1, const char *name2);
+
+U_CAPI int32_t U_EXPORT2
+uprv_compareEBCDICPropertyNames(const char *name1, const char *name2);
+
+#if U_CHARSET_FAMILY==U_ASCII_FAMILY
+# define uprv_comparePropertyNames uprv_compareASCIIPropertyNames
+#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+# define uprv_comparePropertyNames uprv_compareEBCDICPropertyNames
+#else
+# error U_CHARSET_FAMILY is not valid
+#endif
+
+U_CDECL_END
+
+/* UDataMemory structure and signatures ------------------------------------- */
+
+#define PNAME_DATA_NAME "pnames"
+#define PNAME_DATA_TYPE "icu"
+
+/* Fields in UDataInfo: */
+
+/* PNAME_SIG[] is encoded as numeric literals for compatibility with the HP compiler */
+#define PNAME_SIG_0 ((uint8_t)0x70) /* p */
+#define PNAME_SIG_1 ((uint8_t)0x6E) /* n */
+#define PNAME_SIG_2 ((uint8_t)0x61) /* a */
+#define PNAME_SIG_3 ((uint8_t)0x6D) /* m */
+
+#define PNAME_FORMAT_VERSION ((int8_t)1) /* formatVersion[0] */
+
+/**
+ * Swap pnames.icu. See udataswp.h.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+upname_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+
+#ifdef XP_CPLUSPLUS
+
+class Builder;
+
+U_NAMESPACE_BEGIN
+
+/**
+ * An offset from the start of the pnames data to a contained entity.
+ * This must be a signed value, since negative offsets are used as an
+ * end-of-list marker. Offsets to actual objects are non-zero. A
+ * zero offset indicates an absent entry; this corresponds to aliases
+ * marked "n/a" in the original Unicode data files.
+ */
+typedef int16_t Offset; /* must be signed */
+
+#define MAX_OFFSET 0x7FFF
+
+/**
+ * A generic value for a property or property value. Typically an
+ * enum from uchar.h, but sometimes a non-enum value. It must be
+ * large enough to accomodate the largest enum value, which as of this
+ * writing is the largest general category mask. Need not be signed
+ * but may be. Typically it doesn't matter, since the caller will
+ * cast it to the proper type before use. Takes the special value
+ * UCHAR_INVALID_CODE for invalid input.
+ */
+typedef int32_t EnumValue;
+
+/* ---------------------------------------------------------------------- */
+/* ValueMap */
+
+/**
+ * For any top-level property that has named values (binary and
+ * enumerated properties), there is a ValueMap object. This object
+ * maps from enum values to two other maps. One goes from value enums
+ * to value names. The other goes from value names to value enums.
+ *
+ * The value enum values may be contiguous or disjoint. If they are
+ * contiguous then the enumToName_offset is nonzero, and the
+ * ncEnumToName_offset is zero. Vice versa if the value enums are
+ * disjoint.
+ *
+ * There are n of these objects, where n is the number of binary
+ * properties + the number of enumerated properties.
+ */
+struct ValueMap {
+
+ /* -- begin pnames data -- */
+ /* Enum=>name EnumToOffset / NonContiguousEnumToOffset objects. */
+ /* Exactly one of these will be nonzero. */
+ Offset enumToName_offset;
+ Offset ncEnumToName_offset;
+
+ Offset nameToEnum_offset; /* Name=>enum data */
+ /* -- end pnames data -- */
+};
+
+/* ---------------------------------------------------------------------- */
+/* PropertyAliases class */
+
+/**
+ * A class encapsulating access to the memory-mapped data representing
+ * property aliases and property value aliases (pnames). The class
+ * MUST have no v-table and declares certain methods inline -- small
+ * methods and methods that are called from only one point.
+ *
+ * The data members in this class correspond to the in-memory layout
+ * of the header of the pnames data.
+ */
+class PropertyAliases {
+
+ /* -- begin pnames data -- */
+ /* Enum=>name EnumToOffset object for binary and enumerated */
+ /* properties */
+ Offset enumToName_offset;
+
+ /* Name=>enum data for binary & enumerated properties */
+ Offset nameToEnum_offset;
+
+ /* Enum=>offset EnumToOffset object mapping enumerated properties */
+ /* to ValueMap objects */
+ Offset enumToValue_offset;
+
+ /* The following are needed by external readers of this data. */
+ /* We don't use them ourselves. */
+ int16_t total_size; /* size in bytes excluding the udata header */
+ Offset valueMap_offset; /* offset to start of array */
+ int16_t valueMap_count; /* number of entries */
+ Offset nameGroupPool_offset; /* offset to start of array */
+ int16_t nameGroupPool_count; /* number of entries (not groups) */
+ Offset stringPool_offset; /* offset to start of pool */
+ int16_t stringPool_count; /* number of strings (not size in bytes) */
+
+ /* -- end pnames data -- */
+
+ friend class ::Builder;
+
+ const ValueMap* getValueMap(EnumValue prop) const;
+
+ const char* chooseNameInGroup(Offset offset,
+ UPropertyNameChoice choice) const;
+
+ public:
+
+ inline const int8_t* getPointer(Offset o) const {
+ return ((const int8_t*) this) + o;
+ }
+
+ inline const int8_t* getPointerNull(Offset o) const {
+ return o ? getPointer(o) : NULL;
+ }
+
+ inline const char* getPropertyName(EnumValue prop,
+ UPropertyNameChoice choice) const;
+
+ inline EnumValue getPropertyEnum(const char* alias) const;
+
+ inline const char* getPropertyValueName(EnumValue prop, EnumValue value,
+ UPropertyNameChoice choice) const;
+
+ inline EnumValue getPropertyValueEnum(EnumValue prop,
+ const char* alias) const;
+
+ static int32_t
+ swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ UErrorCode *pErrorCode);
+};
+
+/* ---------------------------------------------------------------------- */
+/* EnumToOffset */
+
+/**
+ * A generic map from enum values to Offsets. The enum values must be
+ * contiguous, from enumStart to enumLimit. The Offset values may
+ * point to anything.
+ */
+class EnumToOffset {
+
+ /* -- begin pnames data -- */
+ EnumValue enumStart;
+ EnumValue enumLimit;
+ Offset _offsetArray; /* [array of enumLimit-enumStart] */
+ /* -- end pnames data -- */
+
+ friend class ::Builder;
+
+ Offset* getOffsetArray() {
+ return &_offsetArray;
+ }
+
+ const Offset* getOffsetArray() const {
+ return &_offsetArray;
+ }
+
+ static int32_t getSize(int32_t n) {
+ return sizeof(EnumToOffset) + sizeof(Offset) * (n - 1);
+ }
+
+ int32_t getSize() {
+ return getSize(enumLimit - enumStart);
+ }
+
+ public:
+
+ Offset getOffset(EnumValue enumProbe) const {
+ if (enumProbe < enumStart ||
+ enumProbe >= enumLimit) {
+ return 0; /* not found */
+ }
+ const Offset* p = getOffsetArray();
+ return p[enumProbe - enumStart];
+ }
+
+ static int32_t
+ swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode);
+};
+
+/* ---------------------------------------------------------------------- */
+/* NonContiguousEnumToOffset */
+
+/**
+ * A generic map from enum values to Offsets. The enum values may be
+ * disjoint. If they are contiguous, an EnumToOffset should be used
+ * instead. The Offset values may point to anything.
+ */
+class NonContiguousEnumToOffset {
+
+ /* -- begin pnames data -- */
+ int32_t count;
+ EnumValue _enumArray; /* [array of count] */
+ /* Offset _offsetArray; // [array of count] after enumValue[count-1] */
+ /* -- end pnames data -- */
+
+ friend class ::Builder;
+
+ EnumValue* getEnumArray() {
+ return &_enumArray;
+ }
+
+ const EnumValue* getEnumArray() const {
+ return &_enumArray;
+ }
+
+ Offset* getOffsetArray() {
+ return (Offset*) (getEnumArray() + count);
+ }
+
+ const Offset* getOffsetArray() const {
+ return (Offset*) (getEnumArray() + count);
+ }
+
+ static int32_t getSize(int32_t n) {
+ return sizeof(int32_t) + (sizeof(EnumValue) + sizeof(Offset)) * n;
+ }
+
+ int32_t getSize() {
+ return getSize(count);
+ }
+
+ public:
+
+ Offset getOffset(EnumValue enumProbe) const {
+ const EnumValue* e = getEnumArray();
+ const Offset* p = getOffsetArray();
+ /* linear search; binary later if warranted */
+ /* (binary is not faster for short lists) */
+ for (int32_t i=0; i enumProbe) break;
+ return p[i];
+ }
+ return 0; /* not found */
+ }
+
+ static int32_t
+ swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode);
+};
+
+/* ---------------------------------------------------------------------- */
+/* NameToEnum */
+
+/**
+ * A map from names to enum values.
+ */
+class NameToEnum {
+
+ /* -- begin pnames data -- */
+ int32_t count; /* number of entries */
+ EnumValue _enumArray; /* [array of count] EnumValues */
+ /* Offset _nameArray; // [array of count] offsets to names */
+ /* -- end pnames data -- */
+
+ friend class ::Builder;
+
+ EnumValue* getEnumArray() {
+ return &_enumArray;
+ }
+
+ const EnumValue* getEnumArray() const {
+ return &_enumArray;
+ }
+
+ Offset* getNameArray() {
+ return (Offset*) (getEnumArray() + count);
+ }
+
+ const Offset* getNameArray() const {
+ return (Offset*) (getEnumArray() + count);
+ }
+
+ static int32_t getSize(int32_t n) {
+ return sizeof(int32_t) + (sizeof(Offset) + sizeof(EnumValue)) * n;
+ }
+
+ int32_t getSize() {
+ return getSize(count);
+ }
+
+ public:
+
+ EnumValue getEnum(const char* alias, const PropertyAliases& data) const {
+
+ const Offset* n = getNameArray();
+ const EnumValue* e = getEnumArray();
+
+ /* linear search; binary later if warranted */
+ /* (binary is not faster for short lists) */
+ for (int32_t i=0; i 0) continue;
+ if (c < 0) break;
+ return e[i];
+ }
+
+ return UCHAR_INVALID_CODE;
+ }
+
+ static int32_t
+ swap(const UDataSwapper *ds,
+ const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
+ uint8_t *temp, int32_t pos,
+ UErrorCode *pErrorCode);
+};
+
+/*----------------------------------------------------------------------
+ *
+ * In-memory layout. THIS IS NOT A STANDALONE DOCUMENT. It goes
+ * together with above C++ declarations and gives an overview.
+ *
+ * See above for definitions of Offset and EnumValue. Also, refer to
+ * above class declarations for the "bottom line" on data layout.
+ *
+ * Sizes:
+ * '*_offset' is an Offset (see above)
+ * 'count' members are typically int32_t (see above declarations)
+ * 'enumArray' is an array of EnumValue (see above)
+ * 'offsetArray' is an array of Offset (see above)
+ * 'nameArray' is an array of Offset (see above)
+ * 'enum*' is an EnumValue (see above)
+ * '*Array [x n]' means that *Array has n elements
+ *
+ * References:
+ * Instead of pointers, this flat data structure contains offsets.
+ * All offsets are relative to the start of 'header'. A notation
+ * is used to indicate what structure each offset points to:
+ * 'foo (>x)' the offset(s) in foo point to structure x
+ *
+ * Structures:
+ * Each structure is assigned a number, except for the header,
+ * which is called 'header'. The numbers are not contiguous
+ * for historical reasons. Some structures have sub-parts
+ * that are denoted with a letter, e.g., "5a".
+ *
+ * BEGIN LAYOUT
+ * ============
+ * header:
+ * enumToName_offset (>0)
+ * nameToEnum_offset (>2)
+ * enumToValue_offset (>3)
+ * (alignment padding build in to header)
+ *
+ * The header also contains the following, used by "external readers"
+ * like ICU4J and icuswap.
+ *
+ * // The following are needed by external readers of this data.
+ * // We don't use them ourselves.
+ * int16_t total_size; // size in bytes excluding the udata header
+ * Offset valueMap_offset; // offset to start of array
+ * int16_t valueMap_count; // number of entries
+ * Offset nameGroupPool_offset; // offset to start of array
+ * int16_t nameGroupPool_count; // number of entries (not groups)
+ * Offset stringPool_offset; // offset to start of pool
+ * int16_t stringPool_count; // number of strings (not size in bytes)
+ *
+ * 0: # NonContiguousEnumToOffset obj for props => name groups
+ * count
+ * enumArray [x count]
+ * offsetArray [x count] (>98)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * (1: omitted -- no longer used)
+ *
+ * 2: # NameToEnum obj for binary & enumerated props
+ * count
+ * enumArray [x count]
+ * nameArray [x count] (>99)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * 3: # NonContiguousEnumToOffset obj for enumerated props => ValueMaps
+ * count
+ * enumArray [x count]
+ * offsetArray [x count] (>4)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * 4: # ValueMap array [x one for each enumerated prop i]
+ * enumToName_offset (>5a +2*i) one of these two is NULL, one is not
+ * ncEnumToName_offset (>5b +2*i)
+ * nameToEnums_offset (>6 +2*i)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * for each enumerated prop (either 5a or 5b):
+ *
+ * 5a: # EnumToOffset for enumerated prop's values => name groups
+ * enumStart
+ * enumLimit
+ * offsetArray [x enumLimit - enumStart] (>98)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * 5b: # NonContiguousEnumToOffset for enumerated prop's values => name groups
+ * count
+ * enumArray [x count]
+ * offsetArray [x count] (>98)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * 6: # NameToEnum for enumerated prop's values
+ * count
+ * enumArray [x count]
+ * nameArray [x count] (>99)
+ *
+ * => pad to next 4-byte boundary
+ *
+ * 98: # name group pool {NGP}
+ * [array of Offset values] (>99)
+ *
+ * 99: # string pool {SP}
+ * [pool of nul-terminated char* strings]
+ */
+U_NAMESPACE_END
+
+#endif /* C++ */
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/punycode.c b/Build/source/libs/icu/icu-xetex/common/punycode.c
new file mode 100644
index 00000000000..5376625e71d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/punycode.c
@@ -0,0 +1,580 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2002-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: punycode.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2002jan31
+* created by: Markus W. Scherer
+*/
+
+
+/* This ICU code derived from: */
+/*
+punycode.c 0.4.0 (2001-Nov-17-Sat)
+http://www.cs.berkeley.edu/~amc/idn/
+Adam M. Costello
+http://www.nicemice.net/amc/
+
+Disclaimer and license
+
+ Regarding this entire document or any portion of it (including
+ the pseudocode and C code), the author makes no guarantees and
+ is not responsible for any damage resulting from its use. The
+ author grants irrevocable permission to anyone to use, modify,
+ and distribute it in any way that does not diminish the rights
+ of anyone else to use, modify, and distribute it, provided that
+ redistributed derivative works do not contain misleading author or
+ version information. Derivative works need not be licensed under
+ similar terms.
+*/
+/*
+ * ICU modifications:
+ * - ICU data types and coding conventions
+ * - ICU string buffer handling with implicit source lengths
+ * and destination preflighting
+ * - UTF-16 handling
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_IDNA
+
+#include "ustr_imp.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "punycode.h"
+#include "unicode/ustring.h"
+
+
+/* Punycode ----------------------------------------------------------------- */
+
+/* Punycode parameters for Bootstring */
+#define BASE 36
+#define TMIN 1
+#define TMAX 26
+#define SKEW 38
+#define DAMP 700
+#define INITIAL_BIAS 72
+#define INITIAL_N 0x80
+
+/* "Basic" Unicode/ASCII code points */
+#define _HYPHEN 0X2d
+#define DELIMITER _HYPHEN
+
+#define _ZERO_ 0X30
+#define _NINE 0x39
+
+#define _SMALL_A 0X61
+#define _SMALL_Z 0X7a
+
+#define _CAPITAL_A 0X41
+#define _CAPITAL_Z 0X5a
+
+#define IS_BASIC(c) ((c)<0x80)
+#define IS_BASIC_UPPERCASE(c) (_CAPITAL_A<=(c) && (c)<=_CAPITAL_Z)
+
+/**
+ * digitToBasic() returns the basic code point whose value
+ * (when used for representing integers) is d, which must be in the
+ * range 0 to BASE-1. The lowercase form is used unless the uppercase flag is
+ * nonzero, in which case the uppercase form is used.
+ */
+static U_INLINE char
+digitToBasic(int32_t digit, UBool uppercase) {
+ /* 0..25 map to ASCII a..z or A..Z */
+ /* 26..35 map to ASCII 0..9 */
+ if(digit<26) {
+ if(uppercase) {
+ return (char)(_CAPITAL_A+digit);
+ } else {
+ return (char)(_SMALL_A+digit);
+ }
+ } else {
+ return (char)((_ZERO_-26)+digit);
+ }
+}
+
+/**
+ * basicToDigit[] contains the numeric value of a basic code
+ * point (for use in representing integers) in the range 0 to
+ * BASE-1, or -1 if b is does not represent a value.
+ */
+static const int8_t
+basicToDigit[256]={
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1,
+
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
+
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
+
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+static U_INLINE char
+asciiCaseMap(char b, UBool uppercase) {
+ if(uppercase) {
+ if(_SMALL_A<=b && b<=_SMALL_Z) {
+ b-=(_SMALL_A-_CAPITAL_A);
+ }
+ } else {
+ if(_CAPITAL_A<=b && b<=_CAPITAL_Z) {
+ b+=(_SMALL_A-_CAPITAL_A);
+ }
+ }
+ return b;
+}
+
+/* Punycode-specific Bootstring code ---------------------------------------- */
+
+/*
+ * The following code omits the {parts} of the pseudo-algorithm in the spec
+ * that are not used with the Punycode parameter set.
+ */
+
+/* Bias adaptation function. */
+static int32_t
+adaptBias(int32_t delta, int32_t length, UBool firstTime) {
+ int32_t count;
+
+ if(firstTime) {
+ delta/=DAMP;
+ } else {
+ delta/=2;
+ }
+
+ delta+=delta/length;
+ for(count=0; delta>((BASE-TMIN)*TMAX)/2; count+=BASE) {
+ delta/=(BASE-TMIN);
+ }
+
+ return count+(((BASE-TMIN+1)*delta)/(delta+SKEW));
+}
+
+#define MAX_CP_COUNT 200
+
+U_CFUNC int32_t
+u_strToPunycode(const UChar *src, int32_t srcLength,
+ UChar *dest, int32_t destCapacity,
+ const UBool *caseFlags,
+ UErrorCode *pErrorCode) {
+
+ int32_t cpBuffer[MAX_CP_COUNT];
+ int32_t n, delta, handledCPCount, basicLength, destLength, bias, j, m, q, k, t, srcCPCount;
+ UChar c, c2;
+
+ /* argument checking */
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ if(src==NULL || srcLength<-1 || (dest==NULL && destCapacity!=0)) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /*
+ * Handle the basic code points and
+ * convert extended ones to UTF-32 in cpBuffer (caseFlag in sign bit):
+ */
+ srcCPCount=destLength=0;
+ if(srcLength==-1) {
+ /* NUL-terminated input */
+ for(j=0; /* no condition */; ++j) {
+ if((c=src[j])==0) {
+ break;
+ }
+ if(srcCPCount==MAX_CP_COUNT) {
+ /* too many input code points */
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ if(IS_BASIC(c)) {
+ cpBuffer[srcCPCount++]=0;
+ if(destLength0) {
+ if(destLength state to , but guard against overflow:
+ */
+ if(m-n>(0x7fffffff-MAX_CP_COUNT-delta)/(handledCPCount+1)) {
+ *pErrorCode=U_INTERNAL_PROGRAM_ERROR;
+ return 0;
+ }
+ delta+=(m-n)*(handledCPCount+1);
+ n=m;
+
+ /* Encode a sequence of same code points n */
+ for(j=0; jTMAX) {
+ t=TMAX;
+ }
+ */
+
+ t=k-bias;
+ if(t=(bias+TMAX)) {
+ t=TMAX;
+ }
+
+ if(q0;) {
+ if(src[--j]==DELIMITER) {
+ break;
+ }
+ }
+ destLength=basicLength=destCPCount=j;
+
+ while(j>0) {
+ b=src[--j];
+ if(!IS_BASIC(b)) {
+ *pErrorCode=U_INVALID_CHAR_FOUND;
+ return 0;
+ }
+
+ if(j0 ? basicLength+1 : 0; in=srcLength) {
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ return 0;
+ }
+
+ digit=basicToDigit[(uint8_t)src[in++]];
+ if(digit<0) {
+ *pErrorCode=U_INVALID_CHAR_FOUND;
+ return 0;
+ }
+ if(digit>(0x7fffffff-i)/w) {
+ /* integer overflow */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ return 0;
+ }
+
+ i+=digit*w;
+ /** RAM: comment out the old code for conformance with draft-ietf-idn-punycode-03.txt
+ t=k-bias;
+ if(tTMAX) {
+ t=TMAX;
+ }
+ */
+ t=k-bias;
+ if(t=(bias+TMAX)) {
+ t=TMAX;
+ }
+ if(digit0x7fffffff/(BASE-t)) {
+ /* integer overflow */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ return 0;
+ }
+ w*=BASE-t;
+ }
+
+ /*
+ * Modification from sample code:
+ * Increments destCPCount here,
+ * where needed instead of in for() loop tail.
+ */
+ ++destCPCount;
+ bias=adaptBias(i-oldi, destCPCount, (UBool)(oldi==0));
+
+ /*
+ * i was supposed to wrap around from (incremented) destCPCount to 0,
+ * incrementing n each time, so we'll fix that now:
+ */
+ if(i/destCPCount>(0x7fffffff-n)) {
+ /* integer overflow */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ return 0;
+ }
+
+ n+=i/destCPCount;
+ i%=destCPCount;
+ /* not needed for Punycode: */
+ /* if (decode_digit(n) <= BASE) return punycode_invalid_input; */
+
+ if(n>0x10ffff || UTF_IS_SURROGATE(n)) {
+ /* Unicode code point overflow */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ return 0;
+ }
+
+ /* Insert n at position i of the output: */
+ cpLength=UTF_CHAR_LENGTH(n);
+ if((destLength+cpLength)1) {
+ firstSupplementaryIndex=codeUnitIndex;
+ } else {
+ ++firstSupplementaryIndex;
+ }
+ } else {
+ codeUnitIndex=firstSupplementaryIndex;
+ UTF_FWD_N(dest, codeUnitIndex, destLength, i-codeUnitIndex);
+ }
+
+ /* use the UChar index codeUnitIndex instead of the code point index i */
+ if(codeUnitIndex=64).
+ * U_INDEX_OUTOFBOUNDS_ERROR is set if the limit is exceeded.
+ * @param srcLength Number of UChars in src, or -1 if NUL-terminated.
+ * @param dest Output Punycode array.
+ * @param destCapacity Size of dest.
+ * @param caseFlags Vector of boolean values, one per input UChar,
+ * indicating that the corresponding character is to be
+ * marked for the decoder optionally
+ * uppercasing (TRUE) or lowercasing (FALSE)
+ * the character.
+ * ASCII characters are output directly in the case as marked.
+ * Flags corresponding to trail surrogates are ignored.
+ * If caseFlags==NULL then input characters are not
+ * case-mapped.
+ * @param pErrorCode ICU in/out error code parameter.
+ * U_INVALID_CHAR_FOUND if src contains
+ * unmatched single surrogates.
+ * U_INDEX_OUTOFBOUNDS_ERROR if src contains
+ * too many code points.
+ * @return Number of ASCII characters in puny.
+ *
+ * @see u_strFromPunycode
+ */
+U_CFUNC int32_t
+u_strToPunycode(const UChar *src, int32_t srcLength,
+ UChar *dest, int32_t destCapacity,
+ const UBool *caseFlags,
+ UErrorCode *pErrorCode);
+
+/**
+ * u_strFromPunycode() converts Punycode to Unicode.
+ * The Unicode string will be at most as long (in UChars)
+ * than the Punycode string (in chars).
+ *
+ * @param src Input Punycode string.
+ * @param srcLength Length of puny, or -1 if NUL-terminated
+ * @param dest Output Unicode string buffer.
+ * @param destCapacity Size of dest in number of UChars,
+ * and of caseFlags in numbers of UBools.
+ * @param caseFlags Output array for case flags as
+ * defined by the Punycode string.
+ * The caller should uppercase (TRUE) or lowercase (FASLE)
+ * the corresponding character in dest.
+ * For supplementary characters, only the lead surrogate
+ * is marked, and FALSE is stored for the trail surrogate.
+ * This is redundant and not necessary for ASCII characters
+ * because they are already in the case indicated.
+ * Can be NULL if the case flags are not needed.
+ * @param pErrorCode ICU in/out error code parameter.
+ * U_INVALID_CHAR_FOUND if a non-ASCII character
+ * precedes the last delimiter ('-'),
+ * or if an invalid character (not a-zA-Z0-9) is found
+ * after the last delimiter.
+ * U_ILLEGAL_CHAR_FOUND if the delta sequence is ill-formed.
+ * @return Number of UChars written to dest.
+ *
+ * @see u_strToPunycode
+ */
+U_CFUNC int32_t
+u_strFromPunycode(const UChar *src, int32_t srcLength,
+ UChar *dest, int32_t destCapacity,
+ UBool *caseFlags,
+ UErrorCode *pErrorCode);
+
+#endif /* #if !UCONFIG_NO_IDNA */
+
+#endif
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/putil.c b/Build/source/libs/icu/icu-xetex/common/putil.c
new file mode 100644
index 00000000000..825aa575e55
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/putil.c
@@ -0,0 +1,1675 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* FILE NAME : putil.c (previously putil.cpp and ptypes.cpp)
+*
+* Date Name Description
+* 04/14/97 aliu Creation.
+* 04/24/97 aliu Added getDefaultDataDirectory() and
+* getDefaultLocaleID().
+* 04/28/97 aliu Rewritten to assume Unix and apply general methods
+* for assumed case. Non-UNIX platforms must be
+* special-cased. Rewrote numeric methods dealing
+* with NaN and Infinity to be platform independent
+* over all IEEE 754 platforms.
+* 05/13/97 aliu Restored sign of timezone
+* (semantics are hours West of GMT)
+* 06/16/98 erm Added IEEE_754 stuff, cleaned up isInfinite, isNan,
+* nextDouble..
+* 07/22/98 stephen Added remainder, max, min, trunc
+* 08/13/98 stephen Added isNegativeInfinity, isPositiveInfinity
+* 08/24/98 stephen Added longBitsFromDouble
+* 09/08/98 stephen Minor changes for Mac Port
+* 03/02/99 stephen Removed openFile(). Added AS400 support.
+* Fixed EBCDIC tables
+* 04/15/99 stephen Converted to C.
+* 06/28/99 stephen Removed mutex locking in u_isBigEndian().
+* 08/04/99 jeffrey R. Added OS/2 changes
+* 11/15/99 helena Integrated S/390 IEEE support.
+* 04/26/01 Barry N. OS/400 support for uprv_getDefaultLocaleID
+* 08/15/01 Steven H. OS/400 support for uprv_getDefaultCodepage
+******************************************************************************
+*/
+
+/* Define _XOPEN_SOURCE for Solaris and friends. */
+/* NetBSD needs it to be >= 4 */
+#if !defined(_XOPEN_SOURCE)
+#if __STDC_VERSION__ >= 199901L
+/* It is invalid to compile an XPG3, XPG4, XPG4v2 or XPG5 application using c99 on Solaris */
+#define _XOPEN_SOURCE 600
+#else
+#define _XOPEN_SOURCE 4
+#endif
+#endif
+
+/* Make sure things like readlink and such functions work.
+Poorly upgraded Solaris machines can't have this defined.
+Cleanly installed Solaris can use this #define.
+*/
+#if !defined(_XOPEN_SOURCE_EXTENDED) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199901L)
+#define _XOPEN_SOURCE_EXTENDED 1
+#endif
+
+/* include ICU headers */
+#include "unicode/utypes.h"
+#include "unicode/putil.h"
+#include "unicode/ustring.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "umutex.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "locmap.h"
+#include "ucln_cmn.h"
+
+/* Include standard headers. */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* include system headers */
+#ifdef U_WINDOWS
+# define WIN32_LEAN_AND_MEAN
+# define VC_EXTRALEAN
+# define NOUSER
+# define NOSERVICE
+# define NOIME
+# define NOMCX
+# include
+# include "wintz.h"
+#elif defined(U_CYGWIN) && defined(__STRICT_ANSI__)
+/* tzset isn't defined in strict ANSI on Cygwin. */
+# undef __STRICT_ANSI__
+#elif defined(OS400)
+# include
+# include /* error code structure */
+# include
+# include /* EPT_CALL macro - this include must be after all other "QSYSINCs" */
+# include /* For uprv_maximumPtr */
+#elif defined(XP_MAC)
+# include
+# include
+# include
+# include
+# include
+# include
+# define ICU_NO_USER_DATA_OVERRIDE 1
+#elif defined(OS390)
+#include "unicode/ucnv.h" /* Needed for UCNV_SWAP_LFNL_OPTION_STRING */
+#elif defined(U_DARWIN) || defined(U_LINUX) || defined(U_BSD)
+#include
+#include
+#elif defined(U_QNX)
+#include
+#endif
+
+#ifndef U_WINDOWS
+#include
+#endif
+
+/*
+ * Only include langinfo.h if we have a way to get the codeset. If we later
+ * depend on more feature, we can test on U_HAVE_NL_LANGINFO.
+ *
+ */
+
+#if U_HAVE_NL_LANGINFO_CODESET
+#include
+#endif
+
+/* Define the extension for data files, again... */
+#define DATA_TYPE "dat"
+
+/* Leave this copyright notice here! */
+static const char copyright[] = U_COPYRIGHT_STRING;
+
+/* floating point implementations ------------------------------------------- */
+
+/* We return QNAN rather than SNAN*/
+#define SIGN 0x80000000U
+
+/* Make it easy to define certain types of constants */
+typedef union {
+ int64_t i64; /* This must be defined first in order to allow the initialization to work. This is a C89 feature. */
+ double d64;
+} BitPatternConversion;
+static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000) };
+static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000) };
+
+/*---------------------------------------------------------------------------
+ Platform utilities
+ Our general strategy is to assume we're on a POSIX platform. Platforms which
+ are non-POSIX must declare themselves so. The default POSIX implementation
+ will sometimes work for non-POSIX platforms as well (e.g., the NaN-related
+ functions).
+ ---------------------------------------------------------------------------*/
+
+#if defined(U_WINDOWS) || defined(XP_MAC) || defined(OS400)
+# undef U_POSIX_LOCALE
+#else
+# define U_POSIX_LOCALE 1
+#endif
+
+/*
+ WARNING! u_topNBytesOfDouble and u_bottomNBytesOfDouble
+ can't be properly optimized by the gcc compiler sometimes (i.e. gcc 3.2).
+*/
+#if !IEEE_754
+static char*
+u_topNBytesOfDouble(double* d, int n)
+{
+#if U_IS_BIG_ENDIAN
+ return (char*)d;
+#else
+ return (char*)(d + 1) - n;
+#endif
+}
+#endif
+
+static char*
+u_bottomNBytesOfDouble(double* d, int n)
+{
+#if U_IS_BIG_ENDIAN
+ return (char*)(d + 1) - n;
+#else
+ return (char*)d;
+#endif
+}
+
+#if defined(U_WINDOWS)
+typedef union {
+ int64_t int64;
+ FILETIME fileTime;
+} FileTimeConversion; /* This is like a ULARGE_INTEGER */
+
+/* Number of 100 nanoseconds from 1/1/1601 to 1/1/1970 */
+#define EPOCH_BIAS INT64_C(116444736000000000)
+#define HECTONANOSECOND_PER_MILLISECOND 10000
+
+#endif
+
+/*---------------------------------------------------------------------------
+ Universal Implementations
+ These are designed to work on all platforms. Try these, and if they
+ don't work on your platform, then special case your platform with new
+ implementations.
+---------------------------------------------------------------------------*/
+
+/* Return UTC (GMT) time measured in milliseconds since 0:00 on 1/1/70.*/
+U_CAPI UDate U_EXPORT2
+uprv_getUTCtime()
+{
+#ifdef XP_MAC
+ time_t t, t1, t2;
+ struct tm tmrec;
+
+ uprv_memset( &tmrec, 0, sizeof(tmrec) );
+ tmrec.tm_year = 70;
+ tmrec.tm_mon = 0;
+ tmrec.tm_mday = 1;
+ t1 = mktime(&tmrec); /* seconds of 1/1/1970*/
+
+ time(&t);
+ uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) );
+ t2 = mktime(&tmrec); /* seconds of current GMT*/
+ return (UDate)(t2 - t1) * U_MILLIS_PER_SECOND; /* GMT (or UTC) in seconds since 1970*/
+#elif defined(U_WINDOWS)
+
+ FileTimeConversion winTime;
+ GetSystemTimeAsFileTime(&winTime.fileTime);
+ return (UDate)((winTime.int64 - EPOCH_BIAS) / HECTONANOSECOND_PER_MILLISECOND);
+#else
+/*
+ struct timeval posixTime;
+ gettimeofday(&posixTime, NULL);
+ return (UDate)(((int64_t)posixTime.tv_sec * U_MILLIS_PER_SECOND) + (posixTime.tv_usec/1000));
+*/
+ time_t epochtime;
+ time(&epochtime);
+ return (UDate)epochtime * U_MILLIS_PER_SECOND;
+#endif
+}
+
+/*-----------------------------------------------------------------------------
+ IEEE 754
+ These methods detect and return NaN and infinity values for doubles
+ conforming to IEEE 754. Platforms which support this standard include X86,
+ Mac 680x0, Mac PowerPC, AIX RS/6000, and most others.
+ If this doesn't work on your platform, you have non-IEEE floating-point, and
+ will need to code your own versions. A naive implementation is to return 0.0
+ for getNaN and getInfinity, and false for isNaN and isInfinite.
+ ---------------------------------------------------------------------------*/
+
+U_CAPI UBool U_EXPORT2
+uprv_isNaN(double number)
+{
+#if IEEE_754
+ BitPatternConversion convertedNumber;
+ convertedNumber.d64 = number;
+ /* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
+ return (UBool)((convertedNumber.i64 & U_INT64_MAX) > gInf.i64);
+
+#elif defined(OS390)
+ uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
+ sizeof(uint32_t));
+ uint32_t lowBits = *(uint32_t*)u_bottomNBytesOfDouble(&number,
+ sizeof(uint32_t));
+
+ return ((highBits & 0x7F080000L) == 0x7F080000L) &&
+ (lowBits == 0x00000000L);
+
+#else
+ /* If your platform doesn't support IEEE 754 but *does* have an NaN value,*/
+ /* you'll need to replace this default implementation with what's correct*/
+ /* for your platform.*/
+ return number != number;
+#endif
+}
+
+U_CAPI UBool U_EXPORT2
+uprv_isInfinite(double number)
+{
+#if IEEE_754
+ BitPatternConversion convertedNumber;
+ convertedNumber.d64 = number;
+ /* Infinity is exactly 0x7FF0000000000000U. */
+ return (UBool)((convertedNumber.i64 & U_INT64_MAX) == gInf.i64);
+#elif defined(OS390)
+ uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
+ sizeof(uint32_t));
+ uint32_t lowBits = *(uint32_t*)u_bottomNBytesOfDouble(&number,
+ sizeof(uint32_t));
+
+ return ((highBits & ~SIGN) == 0x70FF0000L) && (lowBits == 0x00000000L);
+
+#else
+ /* If your platform doesn't support IEEE 754 but *does* have an infinity*/
+ /* value, you'll need to replace this default implementation with what's*/
+ /* correct for your platform.*/
+ return number == (2.0 * number);
+#endif
+}
+
+U_CAPI UBool U_EXPORT2
+uprv_isPositiveInfinity(double number)
+{
+#if IEEE_754 || defined(OS390)
+ return (UBool)(number > 0 && uprv_isInfinite(number));
+#else
+ return uprv_isInfinite(number);
+#endif
+}
+
+U_CAPI UBool U_EXPORT2
+uprv_isNegativeInfinity(double number)
+{
+#if IEEE_754 || defined(OS390)
+ return (UBool)(number < 0 && uprv_isInfinite(number));
+
+#else
+ uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
+ sizeof(uint32_t));
+ return((highBits & SIGN) && uprv_isInfinite(number));
+
+#endif
+}
+
+U_CAPI double U_EXPORT2
+uprv_getNaN()
+{
+#if IEEE_754 || defined(OS390)
+ return gNan.d64;
+#else
+ /* If your platform doesn't support IEEE 754 but *does* have an NaN value,*/
+ /* you'll need to replace this default implementation with what's correct*/
+ /* for your platform.*/
+ return 0.0;
+#endif
+}
+
+U_CAPI double U_EXPORT2
+uprv_getInfinity()
+{
+#if IEEE_754 || defined(OS390)
+ return gInf.d64;
+#else
+ /* If your platform doesn't support IEEE 754 but *does* have an infinity*/
+ /* value, you'll need to replace this default implementation with what's*/
+ /* correct for your platform.*/
+ return 0.0;
+#endif
+}
+
+U_CAPI double U_EXPORT2
+uprv_floor(double x)
+{
+ return floor(x);
+}
+
+U_CAPI double U_EXPORT2
+uprv_ceil(double x)
+{
+ return ceil(x);
+}
+
+U_CAPI double U_EXPORT2
+uprv_round(double x)
+{
+ return uprv_floor(x + 0.5);
+}
+
+U_CAPI double U_EXPORT2
+uprv_fabs(double x)
+{
+ return fabs(x);
+}
+
+U_CAPI double U_EXPORT2
+uprv_modf(double x, double* y)
+{
+ return modf(x, y);
+}
+
+U_CAPI double U_EXPORT2
+uprv_fmod(double x, double y)
+{
+ return fmod(x, y);
+}
+
+U_CAPI double U_EXPORT2
+uprv_pow(double x, double y)
+{
+ /* This is declared as "double pow(double x, double y)" */
+ return pow(x, y);
+}
+
+U_CAPI double U_EXPORT2
+uprv_pow10(int32_t x)
+{
+ return pow(10.0, (double)x);
+}
+
+U_CAPI double U_EXPORT2
+uprv_fmax(double x, double y)
+{
+#if IEEE_754
+ int32_t lowBits;
+
+ /* first handle NaN*/
+ if(uprv_isNaN(x) || uprv_isNaN(y))
+ return uprv_getNaN();
+
+ /* check for -0 and 0*/
+ lowBits = *(uint32_t*) u_bottomNBytesOfDouble(&x, sizeof(uint32_t));
+ if(x == 0.0 && y == 0.0 && (lowBits & SIGN))
+ return y;
+
+#endif
+
+ /* this should work for all flt point w/o NaN and Infpecial cases */
+ return (x > y ? x : y);
+}
+
+U_CAPI double U_EXPORT2
+uprv_fmin(double x, double y)
+{
+#if IEEE_754
+ int32_t lowBits;
+
+ /* first handle NaN*/
+ if(uprv_isNaN(x) || uprv_isNaN(y))
+ return uprv_getNaN();
+
+ /* check for -0 and 0*/
+ lowBits = *(uint32_t*) u_bottomNBytesOfDouble(&y, sizeof(uint32_t));
+ if(x == 0.0 && y == 0.0 && (lowBits & SIGN))
+ return y;
+
+#endif
+
+ /* this should work for all flt point w/o NaN and Inf special cases */
+ return (x > y ? y : x);
+}
+
+/**
+ * Truncates the given double.
+ * trunc(3.3) = 3.0, trunc (-3.3) = -3.0
+ * This is different than calling floor() or ceil():
+ * floor(3.3) = 3, floor(-3.3) = -4
+ * ceil(3.3) = 4, ceil(-3.3) = -3
+ */
+U_CAPI double U_EXPORT2
+uprv_trunc(double d)
+{
+#if IEEE_754
+ int32_t lowBits;
+
+ /* handle error cases*/
+ if(uprv_isNaN(d))
+ return uprv_getNaN();
+ if(uprv_isInfinite(d))
+ return uprv_getInfinity();
+
+ lowBits = *(uint32_t*) u_bottomNBytesOfDouble(&d, sizeof(uint32_t));
+ if( (d == 0.0 && (lowBits & SIGN)) || d < 0)
+ return ceil(d);
+ else
+ return floor(d);
+
+#else
+ return d >= 0 ? floor(d) : ceil(d);
+
+#endif
+}
+
+/**
+ * Return the largest positive number that can be represented by an integer
+ * type of arbitrary bit length.
+ */
+U_CAPI double U_EXPORT2
+uprv_maxMantissa(void)
+{
+ return pow(2.0, DBL_MANT_DIG + 1.0) - 1.0;
+}
+
+U_CAPI double U_EXPORT2
+uprv_log(double d)
+{
+ return log(d);
+}
+
+U_CAPI void * U_EXPORT2
+uprv_maximumPtr(void * base)
+{
+#if defined(OS400)
+ /*
+ * With the provided function we should never be out of range of a given segment
+ * (a traditional/typical segment that is). Our segments have 5 bytes for the
+ * id and 3 bytes for the offset. The key is that the casting takes care of
+ * only retrieving the offset portion minus x1000. Hence, the smallest offset
+ * seen in a program is x001000 and when casted to an int would be 0.
+ * That's why we can only add 0xffefff. Otherwise, we would exceed the segment.
+ *
+ * Currently, 16MB is the current addressing limitation on i5/OS if the activation is
+ * non-TERASPACE. If it is TERASPACE it is 2GB - 4k(header information).
+ * This function determines the activation based on the pointer that is passed in and
+ * calculates the appropriate maximum available size for
+ * each pointer type (TERASPACE and non-TERASPACE)
+ *
+ * Unlike other operating systems, the pointer model isn't determined at
+ * compile time on i5/OS.
+ */
+ if ((base != NULL) && (_TESTPTR(base, _C_TERASPACE_CHECK))) {
+ /* if it is a TERASPACE pointer the max is 2GB - 4k */
+ return ((void *)(((char *)base)-((uint32_t)(base))+((uint32_t)0x7fffefff)));
+ }
+ /* otherwise 16MB since NULL ptr is not checkable or the ptr is not TERASPACE */
+ return ((void *)(((char *)base)-((uint32_t)(base))+((uint32_t)0xffefff)));
+
+#else
+ return U_MAX_PTR(base);
+#endif
+}
+
+/*---------------------------------------------------------------------------
+ Platform-specific Implementations
+ Try these, and if they don't work on your platform, then special case your
+ platform with new implementations.
+ ---------------------------------------------------------------------------*/
+
+/* Generic time zone layer -------------------------------------------------- */
+
+/* Time zone utilities */
+U_CAPI void U_EXPORT2
+uprv_tzset()
+{
+#ifdef U_TZSET
+ U_TZSET();
+#else
+ /* no initialization*/
+#endif
+}
+
+U_CAPI int32_t U_EXPORT2
+uprv_timezone()
+{
+#ifdef U_TIMEZONE
+ return U_TIMEZONE;
+#else
+ time_t t, t1, t2;
+ struct tm tmrec;
+ UBool dst_checked;
+ int32_t tdiff = 0;
+
+ time(&t);
+ uprv_memcpy( &tmrec, localtime(&t), sizeof(tmrec) );
+ dst_checked = (tmrec.tm_isdst != 0); /* daylight savings time is checked*/
+ t1 = mktime(&tmrec); /* local time in seconds*/
+ uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) );
+ t2 = mktime(&tmrec); /* GMT (or UTC) in seconds*/
+ tdiff = t2 - t1;
+ /* imitate NT behaviour, which returns same timezone offset to GMT for
+ winter and summer*/
+ if (dst_checked)
+ tdiff += 3600;
+ return tdiff;
+#endif
+}
+
+/* Note that U_TZNAME does *not* have to be tzname, but if it is,
+ some platforms need to have it declared here. */
+
+#if defined(U_TZNAME) && (defined(U_IRIX) || defined(U_DARWIN) || defined(U_CYGWIN))
+/* RS6000 and others reject char **tzname. */
+extern U_IMPORT char *U_TZNAME[];
+#endif
+
+#if !UCONFIG_NO_FILE_IO && (defined(U_DARWIN) || defined(U_LINUX) || defined(U_BSD))
+/* These platforms are likely to use Olson timezone IDs. */
+#define CHECK_LOCALTIME_LINK 1
+#if defined(U_DARWIN)
+#include
+#define TZZONEINFO (TZDIR "/")
+#else
+#define TZDEFAULT "/etc/localtime"
+#define TZZONEINFO "/usr/share/zoneinfo/"
+#endif
+static char gTimeZoneBuffer[PATH_MAX];
+static char *gTimeZoneBufferPtr = NULL;
+#endif
+
+#ifndef U_WINDOWS
+#define isNonDigit(ch) (ch < '0' || '9' < ch)
+static UBool isValidOlsonID(const char *id) {
+ int32_t idx = 0;
+
+ /* Determine if this is something like Iceland (Olson ID)
+ or AST4ADT (non-Olson ID) */
+ while (id[idx] && isNonDigit(id[idx]) && id[idx] != ',') {
+ idx++;
+ }
+
+ /* If we went through the whole string, then it might be okay.
+ The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30",
+ "GRNLNDST3GRNLNDDT" or similar, so we cannot use it.
+ The rest of the time it could be an Olson ID. George */
+ return (UBool)(id[idx] == 0
+ || uprv_strcmp(id, "PST8PDT") == 0
+ || uprv_strcmp(id, "MST7MDT") == 0
+ || uprv_strcmp(id, "CST6CDT") == 0
+ || uprv_strcmp(id, "EST5EDT") == 0);
+}
+#endif
+
+#if defined(U_TZNAME) && !defined(U_WINDOWS)
+
+#define CONVERT_HOURS_TO_SECONDS(offset) (int32_t)(offset*3600)
+typedef struct OffsetZoneMapping {
+ int32_t offsetSeconds;
+ int32_t daylightType; /* 1=daylight in June, 2=daylight in December*/
+ const char *stdID;
+ const char *dstID;
+ const char *olsonID;
+} OffsetZoneMapping;
+
+/*
+This list tries to disambiguate a set of abbreviated timezone IDs and offsets
+and maps it to an Olson ID.
+Before adding anything to this list, take a look at
+icu/source/tools/tzcode/tz.alias
+Sometimes no daylight savings (0) is important to define due to aliases.
+This list can be tested with icu/source/test/compat/tzone.pl
+More values could be added to daylightType to increase precision.
+*/
+static const struct OffsetZoneMapping OFFSET_ZONE_MAPPINGS[] = {
+ {-45900, 2, "CHAST", "CHADT", "Pacific/Chatham"},
+ {-43200, 1, "PETT", "PETST", "Asia/Kamchatka"},
+ {-43200, 2, "NZST", "NZDT", "Pacific/Auckland"},
+ {-43200, 1, "ANAT", "ANAST", "Asia/Anadyr"},
+ {-39600, 1, "MAGT", "MAGST", "Asia/Magadan"},
+ {-37800, 2, "LHST", "LHST", "Australia/Lord_Howe"},
+ {-36000, 2, "EST", "EST", "Australia/Sydney"},
+ {-36000, 1, "SAKT", "SAKST", "Asia/Sakhalin"},
+ {-36000, 1, "VLAT", "VLAST", "Asia/Vladivostok"},
+ {-34200, 2, "CST", "CST", "Australia/South"},
+ {-32400, 1, "YAKT", "YAKST", "Asia/Yakutsk"},
+ {-32400, 1, "CHOT", "CHOST", "Asia/Choibalsan"},
+ {-31500, 2, "CWST", "CWST", "Australia/Eucla"},
+ {-28800, 1, "IRKT", "IRKST", "Asia/Irkutsk"},
+ {-28800, 1, "ULAT", "ULAST", "Asia/Ulaanbaatar"},
+ {-28800, 2, "WST", "WST", "Australia/West"},
+ {-25200, 1, "HOVT", "HOVST", "Asia/Hovd"},
+ {-25200, 1, "KRAT", "KRAST", "Asia/Krasnoyarsk"},
+ {-21600, 1, "NOVT", "NOVST", "Asia/Novosibirsk"},
+ {-21600, 1, "OMST", "OMSST", "Asia/Omsk"},
+ {-18000, 1, "YEKT", "YEKST", "Asia/Yekaterinburg"},
+ {-14400, 1, "SAMT", "SAMST", "Europe/Samara"},
+ {-14400, 1, "AMT", "AMST", "Asia/Yerevan"},
+ {-14400, 1, "AZT", "AZST", "Asia/Baku"},
+ {-10800, 1, "AST", "ADT", "Asia/Baghdad"},
+ {-10800, 1, "MSK", "MSD", "Europe/Moscow"},
+ {-10800, 1, "VOLT", "VOLST", "Europe/Volgograd"},
+ {-7200, 0, "EET", "CEST", "Africa/Tripoli"},
+ {-7200, 1, "EET", "EEST", "Europe/Athens"}, /* Conflicts with Africa/Cairo */
+ {-7200, 1, "IST", "IDT", "Asia/Jerusalem"},
+ {-3600, 0, "CET", "WEST", "Africa/Algiers"},
+ {-3600, 2, "WAT", "WAST", "Africa/Windhoek"},
+ {0, 1, "GMT", "IST", "Europe/Dublin"},
+ {0, 1, "GMT", "BST", "Europe/London"},
+ {0, 0, "WET", "WEST", "Africa/Casablanca"},
+ {0, 0, "WET", "WET", "Africa/El_Aaiun"},
+ {3600, 1, "AZOT", "AZOST", "Atlantic/Azores"},
+ {3600, 1, "EGT", "EGST", "America/Scoresbysund"},
+ {10800, 1, "PMST", "PMDT", "America/Miquelon"},
+ {10800, 2, "UYT", "UYST", "America/Montevideo"},
+ {10800, 1, "WGT", "WGST", "America/Godthab"},
+ {10800, 2, "BRT", "BRST", "Brazil/East"},
+ {12600, 1, "NST", "NDT", "America/St_Johns"},
+ {14400, 1, "AST", "ADT", "Canada/Atlantic"},
+ {14400, 2, "AMT", "AMST", "America/Cuiaba"},
+ {14400, 2, "CLT", "CLST", "Chile/Continental"},
+ {14400, 2, "FKT", "FKST", "Atlantic/Stanley"},
+ {14400, 2, "PYT", "PYST", "America/Asuncion"},
+ {18000, 1, "CST", "CDT", "America/Havana"},
+ {18000, 1, "EST", "EDT", "US/Eastern"}, /* Conflicts with America/Grand_Turk */
+ {21600, 2, "EAST", "EASST", "Chile/EasterIsland"},
+ {21600, 0, "CST", "MDT", "Canada/Saskatchewan"},
+ {21600, 0, "CST", "CDT", "America/Guatemala"},
+ {21600, 1, "CST", "CDT", "US/Central"}, /* Conflicts with Mexico/General */
+ {25200, 1, "MST", "MDT", "US/Mountain"}, /* Conflicts with Mexico/BajaSur */
+ {28800, 0, "PST", "PST", "Pacific/Pitcairn"},
+ {28800, 1, "PST", "PDT", "US/Pacific"}, /* Conflicts with Mexico/BajaNorte */
+ {32400, 1, "AKST", "AKDT", "US/Alaska"},
+ {36000, 1, "HAST", "HADT", "US/Aleutian"}
+};
+
+/*#define DEBUG_TZNAME*/
+
+static const char* remapShortTimeZone(const char *stdID, const char *dstID, int32_t daylightType, int32_t offset)
+{
+ int32_t idx;
+#ifdef DEBUG_TZNAME
+ fprintf(stderr, "TZ=%s std=%s dst=%s daylight=%d offset=%d\n", getenv("TZ"), stdID, dstID, daylightType, offset);
+#endif
+ for (idx = 0; idx < (int32_t)sizeof(OFFSET_ZONE_MAPPINGS)/sizeof(OFFSET_ZONE_MAPPINGS[0]); idx++)
+ {
+ if (offset == OFFSET_ZONE_MAPPINGS[idx].offsetSeconds
+ && daylightType == OFFSET_ZONE_MAPPINGS[idx].daylightType
+ && strcmp(OFFSET_ZONE_MAPPINGS[idx].stdID, stdID) == 0
+ && strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0)
+ {
+ return OFFSET_ZONE_MAPPINGS[idx].olsonID;
+ }
+ }
+ return NULL;
+}
+#endif
+
+U_CAPI const char* U_EXPORT2
+uprv_tzname(int n)
+{
+ const char *tzid = NULL;
+#ifdef U_WINDOWS
+ tzid = uprv_detectWindowsTimeZone();
+
+ if (tzid != NULL) {
+ return tzid;
+ }
+#else
+
+/*#if defined(U_DARWIN)
+ int ret;
+
+ tzid = getenv("TZFILE");
+ if (tzid != NULL) {
+ return tzid;
+ }
+#endif*/
+
+/* This code can be temporarily disabled to test tzname resolution later on. */
+#ifndef DEBUG_TZNAME
+ tzid = getenv("TZ");
+ if (tzid != NULL && isValidOlsonID(tzid))
+ {
+ /* This might be a good Olson ID. */
+ if (uprv_strncmp(tzid, "posix/", 6) == 0
+ || uprv_strncmp(tzid, "right/", 6) == 0)
+ {
+ /* Remove the posix/ or right/ prefix. */
+ tzid += 6;
+ }
+ return tzid;
+ }
+ /* else U_TZNAME will give a better result. */
+#endif
+
+#if defined(CHECK_LOCALTIME_LINK)
+ /* Caller must handle threading issues */
+ if (gTimeZoneBufferPtr == NULL) {
+ /*
+ This is a trick to look at the name of the link to get the Olson ID
+ because the tzfile contents is underspecified.
+ This isn't guaranteed to work because it may not be a symlink.
+ */
+ int32_t ret = (int32_t)readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer));
+ if (0 < ret) {
+ int32_t tzZoneInfoLen = uprv_strlen(TZZONEINFO);
+ gTimeZoneBuffer[ret] = 0;
+ if (uprv_strncmp(gTimeZoneBuffer, TZZONEINFO, tzZoneInfoLen) == 0
+ && isValidOlsonID(gTimeZoneBuffer + tzZoneInfoLen))
+ {
+ return (gTimeZoneBufferPtr = gTimeZoneBuffer + tzZoneInfoLen);
+ }
+ }
+ }
+ else {
+ return gTimeZoneBufferPtr;
+ }
+#endif
+#endif
+
+#ifdef U_TZNAME
+#if !defined(U_WINDOWS)
+ /*
+ U_TZNAME is usually a non-unique abbreviation, which isn't normally usable.
+ So we remap the abbreviation to an olson ID.
+
+ Since Windows exposes a little more timezone information,
+ we normally don't use this code on Windows because
+ uprv_detectWindowsTimeZone should have already given the correct answer.
+ */
+ {
+ struct tm juneSol, decemberSol;
+ int daylightType;
+ static const time_t juneSolstice=1182478260; /*2007-06-21 18:11 UT*/
+ static const time_t decemberSolstice=1198332540; /*2007-12-22 06:09 UT*/
+
+ /* This probing will tell us when daylight savings occurs. */
+ localtime_r(&juneSolstice, &juneSol);
+ localtime_r(&decemberSolstice, &decemberSol);
+ daylightType = ((decemberSol.tm_isdst > 0) << 1) | (juneSol.tm_isdst > 0);
+ tzid = remapShortTimeZone(U_TZNAME[0], U_TZNAME[1], daylightType, uprv_timezone());
+ if (tzid != NULL) {
+ return tzid;
+ }
+ }
+#endif
+ return U_TZNAME[n];
+#else
+ return "";
+#endif
+}
+
+/* Get and set the ICU data directory --------------------------------------- */
+
+static char *gDataDirectory = NULL;
+#if U_POSIX_LOCALE
+ static char *gCorrectedPOSIXLocale = NULL; /* Heap allocated */
+#endif
+
+static UBool U_CALLCONV putil_cleanup(void)
+{
+ if (gDataDirectory && *gDataDirectory) {
+ uprv_free(gDataDirectory);
+ }
+ gDataDirectory = NULL;
+#if U_POSIX_LOCALE
+ if (gCorrectedPOSIXLocale) {
+ uprv_free(gCorrectedPOSIXLocale);
+ gCorrectedPOSIXLocale = NULL;
+ }
+#endif
+ return TRUE;
+}
+
+/*
+ * Set the data directory.
+ * Make a copy of the passed string, and set the global data dir to point to it.
+ * TODO: see bug #2849, regarding thread safety.
+ */
+U_CAPI void U_EXPORT2
+u_setDataDirectory(const char *directory) {
+ char *newDataDir;
+ int32_t length;
+
+ if(directory==NULL || *directory==0) {
+ /* A small optimization to prevent the malloc and copy when the
+ shared library is used, and this is a way to make sure that NULL
+ is never returned.
+ */
+ newDataDir = (char *)"";
+ }
+ else {
+ length=(int32_t)uprv_strlen(directory);
+ newDataDir = (char *)uprv_malloc(length + 2);
+ uprv_strcpy(newDataDir, directory);
+
+#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
+ {
+ char *p;
+ while(p = uprv_strchr(newDataDir, U_FILE_ALT_SEP_CHAR)) {
+ *p = U_FILE_SEP_CHAR;
+ }
+ }
+#endif
+ }
+
+ umtx_lock(NULL);
+ if (gDataDirectory && *gDataDirectory) {
+ uprv_free(gDataDirectory);
+ }
+ gDataDirectory = newDataDir;
+ ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
+ umtx_unlock(NULL);
+}
+
+U_CAPI UBool U_EXPORT2
+uprv_pathIsAbsolute(const char *path)
+{
+ if(!path || !*path) {
+ return FALSE;
+ }
+
+ if(*path == U_FILE_SEP_CHAR) {
+ return TRUE;
+ }
+
+#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
+ if(*path == U_FILE_ALT_SEP_CHAR) {
+ return TRUE;
+ }
+#endif
+
+#if defined(U_WINDOWS)
+ if( (((path[0] >= 'A') && (path[0] <= 'Z')) ||
+ ((path[0] >= 'a') && (path[0] <= 'z'))) &&
+ path[1] == ':' ) {
+ return TRUE;
+ }
+#endif
+
+ return FALSE;
+}
+
+U_CAPI const char * U_EXPORT2
+u_getDataDirectory(void) {
+ const char *path = NULL;
+
+ /* if we have the directory, then return it immediately */
+ UMTX_CHECK(NULL, gDataDirectory, path);
+
+ if(path) {
+ return path;
+ }
+
+ /*
+ When ICU_NO_USER_DATA_OVERRIDE is defined, users aren't allowed to
+ override ICU's data with the ICU_DATA environment variable. This prevents
+ problems where multiple custom copies of ICU's specific version of data
+ are installed on a system. Either the application must define the data
+ directory with u_setDataDirectory, define ICU_DATA_DIR when compiling
+ ICU, set the data with udata_setCommonData or trust that all of the
+ required data is contained in ICU's data library that contains
+ the entry point defined by U_ICUDATA_ENTRY_POINT.
+
+ There may also be some platforms where environment variables
+ are not allowed.
+ */
+# if !defined(ICU_NO_USER_DATA_OVERRIDE) && !UCONFIG_NO_FILE_IO
+ /* First try to get the environment variable */
+ path=getenv("ICU_DATA");
+# endif
+
+ /* ICU_DATA_DIR may be set as a compile option */
+# ifdef ICU_DATA_DIR
+ if(path==NULL || *path==0) {
+ path=ICU_DATA_DIR;
+ }
+# endif
+
+ if(path==NULL) {
+ /* It looks really bad, set it to something. */
+ path = "";
+ }
+
+ u_setDataDirectory(path);
+ return gDataDirectory;
+}
+
+
+
+
+
+/* Macintosh-specific locale information ------------------------------------ */
+#ifdef XP_MAC
+
+typedef struct {
+ int32_t script;
+ int32_t region;
+ int32_t lang;
+ int32_t date_region;
+ const char* posixID;
+} mac_lc_rec;
+
+/* Todo: This will be updated with a newer version from www.unicode.org web
+ page when it's available.*/
+#define MAC_LC_MAGIC_NUMBER -5
+#define MAC_LC_INIT_NUMBER -9
+
+static const mac_lc_rec mac_lc_recs[] = {
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 0, "en_US",
+ /* United States*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 1, "fr_FR",
+ /* France*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 2, "en_GB",
+ /* Great Britain*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 3, "de_DE",
+ /* Germany*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 4, "it_IT",
+ /* Italy*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 5, "nl_NL",
+ /* Metherlands*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 6, "fr_BE",
+ /* French for Belgium or Lxembourg*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 7, "sv_SE",
+ /* Sweden*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 9, "da_DK",
+ /* Denmark*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 10, "pt_PT",
+ /* Portugal*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 11, "fr_CA",
+ /* French Canada*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 13, "is_IS",
+ /* Israel*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 14, "ja_JP",
+ /* Japan*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 15, "en_AU",
+ /* Australia*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 16, "ar_AE",
+ /* the Arabic world (?)*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 17, "fi_FI",
+ /* Finland*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 18, "fr_CH",
+ /* French for Switzerland*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 19, "de_CH",
+ /* German for Switzerland*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 20, "el_GR",
+ /* Greece*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 21, "is_IS",
+ /* Iceland ===*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 22, "",*/
+ /* Malta ===*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 23, "",*/
+ /* Cyprus ===*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 24, "tr_TR",
+ /* Turkey ===*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 25, "sh_YU",
+ /* Croatian system for Yugoslavia*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 33, "",*/
+ /* Hindi system for India*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 34, "",*/
+ /* Pakistan*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 41, "lt_LT",
+ /* Lithuania*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 42, "pl_PL",
+ /* Poland*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 43, "hu_HU",
+ /* Hungary*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 44, "et_EE",
+ /* Estonia*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 45, "lv_LV",
+ /* Latvia*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 46, "",*/
+ /* Lapland [Ask Rich for the data. HS]*/
+ /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 47, "",*/
+ /* Faeroe Islands*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 48, "fa_IR",
+ /* Iran*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 49, "ru_RU",
+ /* Russia*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 50, "en_IE",
+ /* Ireland*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 51, "ko_KR",
+ /* Korea*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 52, "zh_CN",
+ /* People's Republic of China*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 53, "zh_TW",
+ /* Taiwan*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 54, "th_TH",
+ /* Thailand*/
+
+ /* fallback is en_US*/
+ MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER,
+ MAC_LC_MAGIC_NUMBER, "en_US"
+};
+
+#endif
+
+#if U_POSIX_LOCALE
+/* Return just the POSIX id, whatever happens to be in it */
+static const char *uprv_getPOSIXID(void)
+{
+ static const char* posixID = NULL;
+ if (posixID == 0) {
+ /*
+ * On Solaris two different calls to setlocale can result in
+ * different values. Only get this value once.
+ *
+ * We must check this first because an application can set this.
+ *
+ * LC_ALL can't be used because it's platform dependent. The LANG
+ * environment variable seems to affect LC_CTYPE variable by default.
+ * Here is what setlocale(LC_ALL, NULL) can return.
+ * HPUX can return 'C C C C C C C'
+ * Solaris can return /en_US/C/C/C/C/C on the second try.
+ * Linux can return LC_CTYPE=C;LC_NUMERIC=C;...
+ *
+ * The default codepage detection also needs to use LC_CTYPE.
+ *
+ * Do not call setlocale(LC_*, "")! Using an empty string instead
+ * of NULL, will modify the libc behavior.
+ */
+ posixID = setlocale(LC_CTYPE, NULL);
+ if ((posixID == 0)
+ || (uprv_strcmp("C", posixID) == 0)
+ || (uprv_strcmp("POSIX", posixID) == 0))
+ {
+ /* Maybe we got some garbage. Try something more reasonable */
+ posixID = getenv("LC_ALL");
+ if (posixID == 0) {
+ posixID = getenv("LC_CTYPE");
+ if (posixID == 0) {
+ posixID = getenv("LANG");
+ }
+ }
+ }
+
+ if ((posixID==0)
+ || (uprv_strcmp("C", posixID) == 0)
+ || (uprv_strcmp("POSIX", posixID) == 0))
+ {
+ /* Nothing worked. Give it a nice POSIX default value. */
+ posixID = "en_US_POSIX";
+ }
+ }
+
+ return posixID;
+}
+#endif
+
+/* NOTE: The caller should handle thread safety */
+U_CAPI const char* U_EXPORT2
+uprv_getDefaultLocaleID()
+{
+#if U_POSIX_LOCALE
+/*
+ Note that: (a '!' means the ID is improper somehow)
+ LC_ALL ----> default_loc codepage
+--------------------------------------------------------
+ ab.CD ab CD
+ ab@CD ab__CD -
+ ab@CD.EF ab__CD EF
+
+ ab_CD.EF@GH ab_CD_GH EF
+
+Some 'improper' ways to do the same as above:
+ ! ab_CD@GH.EF ab_CD_GH EF
+ ! ab_CD.EF@GH.IJ ab_CD_GH EF
+ ! ab_CD@ZZ.EF@GH.IJ ab_CD_GH EF
+
+ _CD@GH _CD_GH -
+ _CD.EF@GH _CD_GH EF
+
+The variant cannot have dots in it.
+The 'rightmost' variant (@xxx) wins.
+The leftmost codepage (.xxx) wins.
+*/
+ char *correctedPOSIXLocale = 0;
+ const char* posixID = uprv_getPOSIXID();
+ const char *p;
+ const char *q;
+ int32_t len;
+
+ /* Format: (no spaces)
+ ll [ _CC ] [ . MM ] [ @ VV]
+
+ l = lang, C = ctry, M = charmap, V = variant
+ */
+
+ if (gCorrectedPOSIXLocale != NULL) {
+ return gCorrectedPOSIXLocale;
+ }
+
+ if ((p = uprv_strchr(posixID, '.')) != NULL) {
+ /* assume new locale can't be larger than old one? */
+ correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID)+1);
+ uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
+ correctedPOSIXLocale[p-posixID] = 0;
+
+ /* do not copy after the @ */
+ if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
+ correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
+ }
+ }
+
+ /* Note that we scan the *uncorrected* ID. */
+ if ((p = uprv_strrchr(posixID, '@')) != NULL) {
+ if (correctedPOSIXLocale == NULL) {
+ correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID)+1);
+ uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
+ correctedPOSIXLocale[p-posixID] = 0;
+ }
+ p++;
+
+ /* Take care of any special cases here.. */
+ if (!uprv_strcmp(p, "nynorsk")) {
+ p = "NY";
+ /* Don't worry about no__NY. In practice, it won't appear. */
+ }
+
+ if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) {
+ uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b */
+ }
+ else {
+ uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */
+ }
+
+ if ((q = uprv_strchr(p, '.')) != NULL) {
+ /* How big will the resulting string be? */
+ len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
+ uprv_strncat(correctedPOSIXLocale, p, q-p);
+ correctedPOSIXLocale[len] = 0;
+ }
+ else {
+ /* Anything following the @ sign */
+ uprv_strcat(correctedPOSIXLocale, p);
+ }
+
+ /* Should there be a map from 'no@nynorsk' -> no_NO_NY here?
+ * How about 'russian' -> 'ru'?
+ * Many of the other locales using ISO codes will be handled by the
+ * canonicalization functions in uloc_getDefault.
+ */
+ }
+
+ /* Was a correction made? */
+ if (correctedPOSIXLocale != NULL) {
+ posixID = correctedPOSIXLocale;
+ }
+ else {
+ /* copy it, just in case the original pointer goes away. See j2395 */
+ correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
+ posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
+ }
+
+ if (gCorrectedPOSIXLocale == NULL) {
+ gCorrectedPOSIXLocale = correctedPOSIXLocale;
+ ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
+ correctedPOSIXLocale = NULL;
+ }
+
+ if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
+ uprv_free(correctedPOSIXLocale);
+ }
+
+ return posixID;
+
+#elif defined(U_WINDOWS)
+ UErrorCode status = U_ZERO_ERROR;
+ LCID id = GetThreadLocale();
+ const char* locID = uprv_convertToPosix(id, &status);
+
+ if (U_FAILURE(status)) {
+ locID = "en_US";
+ }
+ return locID;
+
+#elif defined(XP_MAC)
+ int32_t script = MAC_LC_INIT_NUMBER;
+ /* = IntlScript(); or GetScriptManagerVariable(smSysScript);*/
+ int32_t region = MAC_LC_INIT_NUMBER;
+ /* = GetScriptManagerVariable(smRegionCode);*/
+ int32_t lang = MAC_LC_INIT_NUMBER;
+ /* = GetScriptManagerVariable(smScriptLang);*/
+ int32_t date_region = MAC_LC_INIT_NUMBER;
+ const char* posixID = 0;
+ int32_t count = sizeof(mac_lc_recs) / sizeof(mac_lc_rec);
+ int32_t i;
+ Intl1Hndl ih;
+
+ ih = (Intl1Hndl) GetIntlResource(1);
+ if (ih)
+ date_region = ((uint16_t)(*ih)->intl1Vers) >> 8;
+
+ for (i = 0; i < count; i++) {
+ if ( ((mac_lc_recs[i].script == MAC_LC_MAGIC_NUMBER)
+ || (mac_lc_recs[i].script == script))
+ && ((mac_lc_recs[i].region == MAC_LC_MAGIC_NUMBER)
+ || (mac_lc_recs[i].region == region))
+ && ((mac_lc_recs[i].lang == MAC_LC_MAGIC_NUMBER)
+ || (mac_lc_recs[i].lang == lang))
+ && ((mac_lc_recs[i].date_region == MAC_LC_MAGIC_NUMBER)
+ || (mac_lc_recs[i].date_region == date_region))
+ )
+ {
+ posixID = mac_lc_recs[i].posixID;
+ break;
+ }
+ }
+
+ return posixID;
+
+#elif defined(OS400)
+ /* locales are process scoped and are by definition thread safe */
+ static char correctedLocale[64];
+ const char *localeID = getenv("LC_ALL");
+ char *p;
+
+ if (localeID == NULL)
+ localeID = getenv("LANG");
+ if (localeID == NULL)
+ localeID = setlocale(LC_ALL, NULL);
+ /* Make sure we have something... */
+ if (localeID == NULL)
+ return "en_US_POSIX";
+
+ /* Extract the locale name from the path. */
+ if((p = uprv_strrchr(localeID, '/')) != NULL)
+ {
+ /* Increment p to start of locale name. */
+ p++;
+ localeID = p;
+ }
+
+ /* Copy to work location. */
+ uprv_strcpy(correctedLocale, localeID);
+
+ /* Strip off the '.locale' extension. */
+ if((p = uprv_strchr(correctedLocale, '.')) != NULL) {
+ *p = 0;
+ }
+
+ /* Upper case the locale name. */
+ T_CString_toUpperCase(correctedLocale);
+
+ /* See if we are using the POSIX locale. Any of the
+ * following are equivalent and use the same QLGPGCMA
+ * (POSIX) locale.
+ * QLGPGCMA2 means UCS2
+ * QLGPGCMA_4 means UTF-32
+ * QLGPGCMA_8 means UTF-8
+ */
+ if ((uprv_strcmp("C", correctedLocale) == 0) ||
+ (uprv_strcmp("POSIX", correctedLocale) == 0) ||
+ (uprv_strncmp("QLGPGCMA", correctedLocale, 8) == 0))
+ {
+ uprv_strcpy(correctedLocale, "en_US_POSIX");
+ }
+ else
+ {
+ int16_t LocaleLen;
+
+ /* Lower case the lang portion. */
+ for(p = correctedLocale; *p != 0 && *p != '_'; p++)
+ {
+ *p = uprv_tolower(*p);
+ }
+
+ /* Adjust for Euro. After '_E' add 'URO'. */
+ LocaleLen = uprv_strlen(correctedLocale);
+ if (correctedLocale[LocaleLen - 2] == '_' &&
+ correctedLocale[LocaleLen - 1] == 'E')
+ {
+ uprv_strcat(correctedLocale, "URO");
+ }
+
+ /* If using Lotus-based locale then convert to
+ * equivalent non Lotus.
+ */
+ else if (correctedLocale[LocaleLen - 2] == '_' &&
+ correctedLocale[LocaleLen - 1] == 'L')
+ {
+ correctedLocale[LocaleLen - 2] = 0;
+ }
+
+ /* There are separate simplified and traditional
+ * locales called zh_HK_S and zh_HK_T.
+ */
+ else if (uprv_strncmp(correctedLocale, "zh_HK", 5) == 0)
+ {
+ uprv_strcpy(correctedLocale, "zh_HK");
+ }
+
+ /* A special zh_CN_GBK locale...
+ */
+ else if (uprv_strcmp(correctedLocale, "zh_CN_GBK") == 0)
+ {
+ uprv_strcpy(correctedLocale, "zh_CN");
+ }
+
+ }
+
+ return correctedLocale;
+#endif
+
+}
+
+#if U_POSIX_LOCALE
+/*
+Due to various platform differences, one platform may specify a charset,
+when they really mean a different charset. Remap the names so that they are
+compatible with ICU. Only conflicting/ambiguous aliases should be resolved
+here. Before adding anything to this function, please consider adding unique
+names to the ICU alias table in the data directory.
+*/
+static const char*
+remapPlatformDependentCodepage(const char *locale, const char *name) {
+ if (locale != NULL && *locale == 0) {
+ /* Make sure that an empty locale is handled the same way. */
+ locale = NULL;
+ }
+ if (name == NULL) {
+ return NULL;
+ }
+#if defined(U_AIX)
+ if (uprv_strcmp(name, "IBM-943") == 0) {
+ /* Use the ASCII compatible ibm-943 */
+ name = "Shift-JIS";
+ }
+ else if (uprv_strcmp(name, "IBM-1252") == 0) {
+ /* Use the windows-1252 that contains the Euro */
+ name = "IBM-5348";
+ }
+#elif defined(U_SOLARIS)
+ if (locale != NULL && uprv_strcmp(name, "EUC") == 0) {
+ /* Solaris underspecifies the "EUC" name. */
+ if (uprv_strcmp(locale, "zh_CN") == 0) {
+ name = "EUC-CN";
+ }
+ else if (uprv_strcmp(locale, "zh_TW") == 0) {
+ name = "EUC-TW";
+ }
+ else if (uprv_strcmp(locale, "ko_KR") == 0) {
+ name = "EUC-KR";
+ }
+ }
+ else if (uprv_strcmp(name, "eucJP") == 0) {
+ /*
+ ibm-954 is the best match.
+ ibm-33722 is the default for eucJP (similar to Windows).
+ */
+ name = "eucjis";
+ }
+#elif defined(U_DARWIN)
+ if (locale == NULL && *name == 0) {
+ /*
+ No locale was specified, and an empty name was passed in.
+ This usually indicates that nl_langinfo didn't return valid information.
+ Mac OS X uses UTF-8 by default (especially the locale data and console).
+ */
+ name = "UTF-8";
+ }
+#elif defined(U_HPUX)
+ if (uprv_strcmp(name, "eucJP") == 0) {
+ /*
+ ibm-1350 is the best match, but unavailable.
+ ibm-954 is mostly a superset of ibm-1350.
+ ibm-33722 is the default for eucJP (similar to Windows).
+ */
+ name = "eucjis";
+ }
+#elif defined(U_LINUX)
+ if (locale != NULL && uprv_strcmp(name, "euc") == 0) {
+ /* Linux underspecifies the "EUC" name. */
+ if (uprv_strcmp(locale, "korean") == 0) {
+ name = "EUC-KR";
+ }
+ else if (uprv_strcmp(locale, "japanese") == 0) {
+ /* See comment below about eucJP */
+ name = "eucjis";
+ }
+ }
+ else if (uprv_strcmp(name, "eucjp") == 0) {
+ /*
+ ibm-1350 is the best match, but unavailable.
+ ibm-954 is mostly a superset of ibm-1350.
+ ibm-33722 is the default for eucJP (similar to Windows).
+ */
+ name = "eucjis";
+ }
+#endif
+ /* return NULL when "" is passed in */
+ if (*name == 0) {
+ name = NULL;
+ }
+ return name;
+}
+
+static const char*
+getCodepageFromPOSIXID(const char *localeName, char * buffer, int32_t buffCapacity)
+{
+ char localeBuf[100];
+ const char *name = NULL;
+ char *variant = NULL;
+
+ if (localeName != NULL && (name = (uprv_strchr(localeName, '.'))) != NULL) {
+ size_t localeCapacity = uprv_min(sizeof(localeBuf), (name-localeName)+1);
+ uprv_strncpy(localeBuf, localeName, localeCapacity);
+ localeBuf[localeCapacity-1] = 0; /* ensure NULL termination */
+ name = uprv_strncpy(buffer, name+1, buffCapacity);
+ buffer[buffCapacity-1] = 0; /* ensure NULL termination */
+ if ((variant = (uprv_strchr(name, '@'))) != NULL) {
+ *variant = 0;
+ }
+ name = remapPlatformDependentCodepage(localeBuf, name);
+ }
+ return name;
+}
+#endif
+
+static const char*
+int_getDefaultCodepage()
+{
+#if defined(OS400)
+ uint32_t ccsid = 37; /* Default to ibm-37 */
+ static char codepage[64];
+ Qwc_JOBI0400_t jobinfo;
+ Qus_EC_t error = { sizeof(Qus_EC_t) }; /* SPI error code */
+
+ EPT_CALL(QUSRJOBI)(&jobinfo, sizeof(jobinfo), "JOBI0400",
+ "* ", " ", &error);
+
+ if (error.Bytes_Available == 0) {
+ if (jobinfo.Coded_Char_Set_ID != 0xFFFF) {
+ ccsid = (uint32_t)jobinfo.Coded_Char_Set_ID;
+ }
+ else if (jobinfo.Default_Coded_Char_Set_Id != 0xFFFF) {
+ ccsid = (uint32_t)jobinfo.Default_Coded_Char_Set_Id;
+ }
+ /* else use the default */
+ }
+ sprintf(codepage,"ibm-%d", ccsid);
+ return codepage;
+
+#elif defined(OS390)
+ static char codepage[64];
+ sprintf(codepage,"%63s" UCNV_SWAP_LFNL_OPTION_STRING, nl_langinfo(CODESET));
+ codepage[63] = 0; /* NULL terminate */
+ return codepage;
+
+#elif defined(XP_MAC)
+ return "macintosh"; /* TODO: Macintosh Roman. There must be a better way. fixme! */
+
+#elif defined(U_WINDOWS)
+ static char codepage[64];
+ sprintf(codepage, "windows-%d", GetACP());
+ return codepage;
+
+#elif U_POSIX_LOCALE
+ static char codesetName[100];
+ const char *localeName = NULL;
+ const char *name = NULL;
+
+ uprv_memset(codesetName, 0, sizeof(codesetName));
+
+ /* Use setlocale in a nice way, and then check some environment variables.
+ Maybe the application used setlocale already.
+ */
+ localeName = uprv_getPOSIXID();
+ name = getCodepageFromPOSIXID(localeName, codesetName, sizeof(codesetName));
+ if (name) {
+ /* if we can find the codeset name from setlocale, return that. */
+ return name;
+ }
+ /* else "C" was probably returned. That's underspecified. */
+
+#if U_HAVE_NL_LANGINFO_CODESET
+ if (*codesetName) {
+ uprv_memset(codesetName, 0, sizeof(codesetName));
+ }
+ /* When available, check nl_langinfo because it usually gives more
+ useful names. It depends on LC_CTYPE and not LANG or LC_ALL.
+ nl_langinfo may use the same buffer as setlocale. */
+ {
+ const char *codeset = nl_langinfo(U_NL_LANGINFO_CODESET);
+ codeset = remapPlatformDependentCodepage(NULL, codeset);
+ if (codeset != NULL) {
+ uprv_strncpy(codesetName, codeset, sizeof(codesetName));
+ codesetName[sizeof(codesetName)-1] = 0;
+ return codesetName;
+ }
+ }
+#endif
+
+ if (*codesetName == 0)
+ {
+ /* Everything failed. Return US ASCII (ISO 646). */
+ (void)uprv_strcpy(codesetName, "US-ASCII");
+ }
+ return codesetName;
+#else
+ return "US-ASCII";
+#endif
+}
+
+
+U_CAPI const char* U_EXPORT2
+uprv_getDefaultCodepage()
+{
+ static char const *name = NULL;
+ umtx_lock(NULL);
+ if (name == NULL) {
+ name = int_getDefaultCodepage();
+ }
+ umtx_unlock(NULL);
+ return name;
+}
+
+
+/* end of platform-specific implementation -------------- */
+
+/* version handling --------------------------------------------------------- */
+
+U_CAPI void U_EXPORT2
+u_versionFromString(UVersionInfo versionArray, const char *versionString) {
+ char *end;
+ uint16_t part=0;
+
+ if(versionArray==NULL) {
+ return;
+ }
+
+ if(versionString!=NULL) {
+ for(;;) {
+ versionArray[part]=(uint8_t)uprv_strtoul(versionString, &end, 10);
+ if(end==versionString || ++part==U_MAX_VERSION_LENGTH || *end!=U_VERSION_DELIMITER) {
+ break;
+ }
+ versionString=end+1;
+ }
+ }
+
+ while(part0 && versionArray[count-1]==0; --count) {
+ }
+
+ if(count <= 1) {
+ count = 2;
+ }
+
+ /* write the first part */
+ /* write the decimal field value */
+ field=versionArray[0];
+ if(field>=100) {
+ *versionString++=(char)('0'+field/100);
+ field%=100;
+ }
+ if(field>=10) {
+ *versionString++=(char)('0'+field/10);
+ field%=10;
+ }
+ *versionString++=(char)('0'+field);
+
+ /* write the following parts */
+ for(part=1; part=100) {
+ *versionString++=(char)('0'+field/100);
+ field%=100;
+ }
+ if(field>=10) {
+ *versionString++=(char)('0'+field/10);
+ field%=10;
+ }
+ *versionString++=(char)('0'+field);
+ }
+
+ /* NUL-terminate */
+ *versionString=0;
+}
+
+U_CAPI void U_EXPORT2
+u_getVersion(UVersionInfo versionArray) {
+ u_versionFromString(versionArray, U_ICU_VERSION);
+}
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/putilimp.h b/Build/source/libs/icu/icu-xetex/common/putilimp.h
new file mode 100644
index 00000000000..c516821e84b
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/putilimp.h
@@ -0,0 +1,277 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1997-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* FILE NAME : putilimp.h
+*
+* Date Name Description
+* 10/17/04 grhoten Move internal functions from putil.h to this file.
+******************************************************************************
+*/
+
+#ifndef PUTILIMP_H
+#define PUTILIMP_H
+
+#include "unicode/utypes.h"
+#include "unicode/putil.h"
+
+/*==========================================================================*/
+/* Platform utilities */
+/*==========================================================================*/
+
+/**
+ * Platform utilities isolates the platform dependencies of the
+ * libarary. For each platform which this code is ported to, these
+ * functions may have to be re-implemented.
+ */
+
+/**
+ * Floating point utility to determine if a double is Not a Number (NaN).
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 uprv_isNaN(double d);
+/**
+ * Floating point utility to determine if a double has an infinite value.
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 uprv_isInfinite(double d);
+/**
+ * Floating point utility to determine if a double has a positive infinite value.
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 uprv_isPositiveInfinity(double d);
+/**
+ * Floating point utility to determine if a double has a negative infinite value.
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 uprv_isNegativeInfinity(double d);
+/**
+ * Floating point utility that returns a Not a Number (NaN) value.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_getNaN(void);
+/**
+ * Floating point utility that returns an infinite value.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_getInfinity(void);
+
+/**
+ * Floating point utility to truncate a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_trunc(double d);
+/**
+ * Floating point utility to calculate the floor of a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_floor(double d);
+/**
+ * Floating point utility to calculate the ceiling of a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_ceil(double d);
+/**
+ * Floating point utility to calculate the absolute value of a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_fabs(double d);
+/**
+ * Floating point utility to calculate the fractional and integer parts of a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_modf(double d, double* pinteger);
+/**
+ * Floating point utility to calculate the remainder of a double divided by another double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_fmod(double d, double y);
+/**
+ * Floating point utility to calculate d to the power of exponent (d^exponent).
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_pow(double d, double exponent);
+/**
+ * Floating point utility to calculate 10 to the power of exponent (10^exponent).
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_pow10(int32_t exponent);
+/**
+ * Floating point utility to calculate the maximum value of two doubles.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_fmax(double d, double y);
+/**
+ * Floating point utility to calculate the minimum value of two doubles.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_fmin(double d, double y);
+/**
+ * Private utility to calculate the maximum value of two integers.
+ * @internal
+ */
+U_INTERNAL int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y);
+/**
+ * Private utility to calculate the minimum value of two integers.
+ * @internal
+ */
+U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y);
+
+#if U_IS_BIG_ENDIAN
+# define uprv_isNegative(number) (*((signed char *)&(number))<0)
+#else
+# define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0)
+#endif
+
+/**
+ * Return the largest positive number that can be represented by an integer
+ * type of arbitrary bit length.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_maxMantissa(void);
+
+/**
+ * Floating point utility to calculate the logarithm of a double.
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_log(double d);
+
+/**
+ * Does common notion of rounding e.g. uprv_floor(x + 0.5);
+ * @param x the double number
+ * @return the rounded double
+ * @internal
+ */
+U_INTERNAL double U_EXPORT2 uprv_round(double x);
+
+#if 0
+/**
+ * Returns the number of digits after the decimal point in a double number x.
+ *
+ * @param x the double number
+ * @return the number of digits after the decimal point in a double number x.
+ * @internal
+ */
+/*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/
+#endif
+
+/**
+ * Time zone utilities
+ *
+ * Wrappers for C runtime library functions relating to timezones.
+ * The t_tzset() function (similar to tzset) uses the current setting
+ * of the environment variable TZ to assign values to three global
+ * variables: daylight, timezone, and tzname. These variables have the
+ * following meanings, and are declared in <time.h>.
+ *
+ * daylight Nonzero if daylight-saving-time zone (DST) is specified
+ * in TZ; otherwise, 0. Default value is 1.
+ * timezone Difference in seconds between coordinated universal
+ * time and local time. E.g., -28,800 for PST (GMT-8hrs)
+ * tzname(0) Three-letter time-zone name derived from TZ environment
+ * variable. E.g., "PST".
+ * tzname(1) Three-letter DST zone name derived from TZ environment
+ * variable. E.g., "PDT". If DST zone is omitted from TZ,
+ * tzname(1) is an empty string.
+ *
+ * Notes: For example, to set the TZ environment variable to correspond
+ * to the current time zone in Germany, you can use one of the
+ * following statements:
+ *
+ * set TZ=GST1GDT
+ * set TZ=GST+1GDT
+ *
+ * If the TZ value is not set, t_tzset() attempts to use the time zone
+ * information specified by the operating system. Under Windows NT
+ * and Windows 95, this information is specified in the Control Panel's
+ * Date/Time application.
+ * @internal
+ */
+U_INTERNAL void U_EXPORT2 uprv_tzset(void);
+
+/**
+ * Difference in seconds between coordinated universal
+ * time and local time. E.g., -28,800 for PST (GMT-8hrs)
+ * @return the difference in seconds between coordinated universal time and local time.
+ * @internal
+ */
+U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void);
+
+/**
+ * tzname(0) Three-letter time-zone name derived from TZ environment
+ * variable. E.g., "PST".
+ * tzname(1) Three-letter DST zone name derived from TZ environment
+ * variable. E.g., "PDT". If DST zone is omitted from TZ,
+ * tzname(1) is an empty string.
+ * @internal
+ */
+U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n);
+
+/**
+ * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
+ * @return the UTC time measured in milliseconds
+ * @internal
+ */
+U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void);
+
+/**
+ * Determine whether a pathname is absolute or not, as defined by the platform.
+ * @param path Pathname to test
+ * @return TRUE if the path is absolute
+ * @internal (ICU 3.0)
+ */
+U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path);
+
+/**
+ * Use U_MAX_PTR instead of this function.
+ * @param void pointer to test
+ * @return the largest possible pointer greater than the base
+ * @internal (ICU 3.8)
+ */
+U_INTERNAL void * U_EXPORT2 uprv_maximumPtr(void *base);
+
+/**
+ * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer.
+ * In fact, buffer sizes must not exceed 2GB so that the difference between
+ * the buffer limit and the buffer start can be expressed in an int32_t.
+ *
+ * The definition of U_MAX_PTR must fulfill the following conditions:
+ * - return the largest possible pointer greater than base
+ * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
+ * - avoid wrapping around at high addresses
+ * - make sure that the returned pointer is not farther from base than 0x7fffffff
+ *
+ * @param base The beginning of a buffer to find the maximum offset from
+ * @internal
+ */
+#ifndef U_MAX_PTR
+# if defined(OS390) && !defined(_LP64)
+ /* We have 31-bit pointers. */
+# define U_MAX_PTR(base) ((void *)0x7fffffff)
+# elif defined(OS400)
+# define U_MAX_PTR(base) uprv_maximumPtr((void *)base)
+# elif defined(__GNUC__) && __GNUC__ >= 4
+/*
+ * Due to a compiler optimization bug, gcc 4 causes test failures when doing
+ * this math arithmetic on pointers on some platforms. It seems like the
+ * pointers are considered signed instead of unsigned. The uintptr_t type
+ * isn't available on all platforms (i.e MSVC 6) and pointers aren't always
+ * a scalar value (i.e. i5/OS see uprv_maximumPtr function).
+ */
+# define U_MAX_PTR(base) \
+ ((void *)(((uintptr_t)(base)+0x7fffffffu) > (uintptr_t)(base) \
+ ? ((uintptr_t)(base)+0x7fffffffu) \
+ : (uintptr_t)-1))
+# else
+# define U_MAX_PTR(base) \
+ ((char *)(((char *)(base)+0x7fffffffu) > (char *)(base) \
+ ? ((char *)(base)+0x7fffffffu) \
+ : (char *)-1))
+# endif
+#endif
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbi.cpp b/Build/source/libs/icu/icu-xetex/common/rbbi.cpp
new file mode 100644
index 00000000000..41d242fff9c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbi.cpp
@@ -0,0 +1,1832 @@
+/*
+***************************************************************************
+* Copyright (C) 1999-2007 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+//
+// file: rbbi.c Contains the implementation of the rule based break iterator
+// runtime engine and the API implementation for
+// class RuleBasedBreakIterator
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/rbbi.h"
+#include "unicode/schriter.h"
+#include "unicode/uchriter.h"
+#include "unicode/udata.h"
+#include "unicode/uclean.h"
+#include "rbbidata.h"
+#include "rbbirb.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "umutex.h"
+#include "ucln_cmn.h"
+#include "brkeng.h"
+
+#include "uassert.h"
+#include "uvector.h"
+
+// if U_LOCAL_SERVICE_HOOK is defined, then localsvc.cpp is expected to be included.
+#if U_LOCAL_SERVICE_HOOK
+#include "localsvc.h"
+#endif
+
+#ifdef RBBI_DEBUG
+static UBool fTrace = FALSE;
+#endif
+
+U_NAMESPACE_BEGIN
+
+
+static const int16_t START_STATE = 1; // The state number of the starting state
+static const int16_t STOP_STATE = 0; // The state-transition value indicating "stop"
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedBreakIterator)
+
+
+//=======================================================================
+// constructors
+//=======================================================================
+
+/**
+ * Constructs a RuleBasedBreakIterator that uses the already-created
+ * tables object that is passed in as a parameter.
+ */
+RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status)
+{
+ init();
+ fData = new RBBIDataWrapper(data, status); // status checked in constructor
+ if (U_FAILURE(status)) {return;}
+ if(fData == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+}
+
+//-------------------------------------------------------------------------------
+//
+// Constructor from a UDataMemory handle to precompiled break rules
+// stored in an ICU data file.
+//
+//-------------------------------------------------------------------------------
+RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &status)
+{
+ init();
+ fData = new RBBIDataWrapper(udm, status); // status checked in constructor
+ if (U_FAILURE(status)) {return;}
+ if(fData == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+}
+
+
+
+//-------------------------------------------------------------------------------
+//
+// Constructor from a set of rules supplied as a string.
+//
+//-------------------------------------------------------------------------------
+RuleBasedBreakIterator::RuleBasedBreakIterator( const UnicodeString &rules,
+ UParseError &parseError,
+ UErrorCode &status)
+{
+ init();
+ if (U_FAILURE(status)) {return;}
+ RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)
+ RBBIRuleBuilder::createRuleBasedBreakIterator(rules, parseError, status);
+ // Note: This is a bit awkward. The RBBI ruleBuilder has a factory method that
+ // creates and returns a complete RBBI. From here, in a constructor, we
+ // can't just return the object created by the builder factory, hence
+ // the assignment of the factory created object to "this".
+ if (U_SUCCESS(status)) {
+ *this = *bi;
+ delete bi;
+ }
+}
+
+
+//-------------------------------------------------------------------------------
+//
+// Default Constructor. Create an empty shell that can be set up later.
+// Used when creating a RuleBasedBreakIterator from a set
+// of rules.
+//-------------------------------------------------------------------------------
+RuleBasedBreakIterator::RuleBasedBreakIterator() {
+ init();
+}
+
+
+//-------------------------------------------------------------------------------
+//
+// Copy constructor. Will produce a break iterator with the same behavior,
+// and which iterates over the same text, as the one passed in.
+//
+//-------------------------------------------------------------------------------
+RuleBasedBreakIterator::RuleBasedBreakIterator(const RuleBasedBreakIterator& other)
+: BreakIterator(other)
+{
+ this->init();
+ *this = other;
+}
+
+
+/**
+ * Destructor
+ */
+RuleBasedBreakIterator::~RuleBasedBreakIterator() {
+ if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {
+ // fCharIter was adopted from the outside.
+ delete fCharIter;
+ }
+ fCharIter = NULL;
+ delete fSCharIter;
+ fCharIter = NULL;
+ delete fDCharIter;
+ fDCharIter = NULL;
+
+ utext_close(fText);
+
+ if (fData != NULL) {
+ fData->removeReference();
+ fData = NULL;
+ }
+ if (fCachedBreakPositions) {
+ uprv_free(fCachedBreakPositions);
+ fCachedBreakPositions = NULL;
+ }
+ if (fLanguageBreakEngines) {
+ delete fLanguageBreakEngines;
+ fLanguageBreakEngines = NULL;
+ }
+ if (fUnhandledBreakEngine) {
+ delete fUnhandledBreakEngine;
+ fUnhandledBreakEngine = NULL;
+ }
+}
+
+/**
+ * Assignment operator. Sets this iterator to have the same behavior,
+ * and iterate over the same text, as the one passed in.
+ */
+RuleBasedBreakIterator&
+RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) {
+ if (this == &that) {
+ return *this;
+ }
+ reset(); // Delete break cache information
+ fBreakType = that.fBreakType;
+ if (fLanguageBreakEngines != NULL) {
+ delete fLanguageBreakEngines;
+ fLanguageBreakEngines = NULL; // Just rebuild for now
+ }
+ // TODO: clone fLanguageBreakEngines from "that"
+ UErrorCode status = U_ZERO_ERROR;
+ fText = utext_clone(fText, that.fText, FALSE, TRUE, &status);
+
+ if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {
+ delete fCharIter;
+ }
+ fCharIter = NULL;
+
+ if (that.fCharIter != NULL ) {
+ // This is a little bit tricky - it will intially appear that
+ // this->fCharIter is adopted, even if that->fCharIter was
+ // not adopted. That's ok.
+ fCharIter = that.fCharIter->clone();
+ }
+
+ if (fData != NULL) {
+ fData->removeReference();
+ fData = NULL;
+ }
+ if (that.fData != NULL) {
+ fData = that.fData->addReference();
+ }
+
+ return *this;
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// init() Shared initialization routine. Used by all the constructors.
+// Initializes all fields, leaving the object in a consistent state.
+//
+//-----------------------------------------------------------------------------
+void RuleBasedBreakIterator::init() {
+ UErrorCode status = U_ZERO_ERROR;
+ fBufferClone = FALSE;
+ fText = utext_openUChars(NULL, NULL, 0, &status);
+ fCharIter = NULL;
+ fSCharIter = NULL;
+ fDCharIter = NULL;
+ fData = NULL;
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ fDictionaryCharCount = 0;
+ fBreakType = -1;
+
+ fCachedBreakPositions = NULL;
+ fLanguageBreakEngines = NULL;
+ fUnhandledBreakEngine = NULL;
+ fNumCachedBreakPositions = 0;
+ fPositionInCache = 0;
+
+#ifdef RBBI_DEBUG
+ static UBool debugInitDone = FALSE;
+ if (debugInitDone == FALSE) {
+ char *debugEnv = getenv("U_RBBIDEBUG");
+ if (debugEnv && uprv_strstr(debugEnv, "trace")) {
+ fTrace = TRUE;
+ }
+ debugInitDone = TRUE;
+ }
+#endif
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// clone - Returns a newly-constructed RuleBasedBreakIterator with the same
+// behavior, and iterating over the same text, as this one.
+// Virtual function: does the right thing with subclasses.
+//
+//-----------------------------------------------------------------------------
+BreakIterator*
+RuleBasedBreakIterator::clone(void) const {
+ return new RuleBasedBreakIterator(*this);
+}
+
+/**
+ * Equality operator. Returns TRUE if both BreakIterators are of the
+ * same class, have the same behavior, and iterate over the same text.
+ */
+UBool
+RuleBasedBreakIterator::operator==(const BreakIterator& that) const {
+ if (that.getDynamicClassID() != getDynamicClassID()) {
+ return FALSE;
+ }
+
+ const RuleBasedBreakIterator& that2 = (const RuleBasedBreakIterator&) that;
+
+ if (!utext_equals(fText, that2.fText)) {
+ // The two break iterators are operating on different text,
+ // or have a different interation position.
+ return FALSE;
+ };
+
+ // TODO: need a check for when in a dictionary region at different offsets.
+
+ if (that2.fData == fData ||
+ (fData != NULL && that2.fData != NULL && *that2.fData == *fData)) {
+ // The two break iterators are using the same rules.
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * Compute a hash code for this BreakIterator
+ * @return A hash code
+ */
+int32_t
+RuleBasedBreakIterator::hashCode(void) const {
+ int32_t hash = 0;
+ if (fData != NULL) {
+ hash = fData->hashCode();
+ }
+ return hash;
+}
+
+
+void RuleBasedBreakIterator::setText(UText *ut, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ reset();
+ fText = utext_clone(fText, ut, FALSE, TRUE, &status);
+
+ // Set up a dummy CharacterIterator to be returned if anyone
+ // calls getText(). With input from UText, there is no reasonable
+ // way to return a characterIterator over the actual input text.
+ // Return one over an empty string instead - this is the closest
+ // we can come to signaling a failure.
+ // (GetText() is obsolete, this failure is sort of OK)
+ if (fDCharIter == NULL) {
+ static UChar c = 0;
+ fDCharIter = new UCharCharacterIterator(&c, 0);
+ }
+
+ if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {
+ // existing fCharIter was adopted from the outside. Delete it now.
+ delete fCharIter;
+ }
+ fCharIter = fDCharIter;
+
+ this->first();
+}
+
+
+UText *RuleBasedBreakIterator::getUText(UText *fillIn, UErrorCode &status) const {
+ UText *result = utext_clone(fillIn, fText, FALSE, TRUE, &status);
+ return result;
+}
+
+
+
+/**
+ * Returns the description used to create this iterator
+ */
+const UnicodeString&
+RuleBasedBreakIterator::getRules() const {
+ if (fData != NULL) {
+ return fData->getRuleSourceString();
+ } else {
+ static const UnicodeString *s;
+ if (s == NULL) {
+ // TODO: something more elegant here.
+ // perhaps API should return the string by value.
+ // Note: thread unsafe init & leak are semi-ok, better than
+ // what was before. Sould be cleaned up, though.
+ s = new UnicodeString;
+ }
+ return *s;
+ }
+}
+
+//=======================================================================
+// BreakIterator overrides
+//=======================================================================
+
+/**
+ * Return a CharacterIterator over the text being analyzed.
+ */
+CharacterIterator&
+RuleBasedBreakIterator::getText() const {
+ return *fCharIter;
+}
+
+/**
+ * Set the iterator to analyze a new piece of text. This function resets
+ * the current iteration position to the beginning of the text.
+ * @param newText An iterator over the text to analyze.
+ */
+void
+RuleBasedBreakIterator::adoptText(CharacterIterator* newText) {
+ // If we are holding a CharacterIterator adopted from a
+ // previous call to this function, delete it now.
+ if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {
+ delete fCharIter;
+ }
+
+ fCharIter = newText;
+ UErrorCode status = U_ZERO_ERROR;
+ reset();
+ if (newText==NULL || newText->startIndex() != 0) {
+ // startIndex !=0 wants to be an error, but there's no way to report it.
+ // Make the iterator text be an empty string.
+ fText = utext_openUChars(fText, NULL, 0, &status);
+ } else {
+ fText = utext_openCharacterIterator(fText, newText, &status);
+ }
+ this->first();
+}
+
+/**
+ * Set the iterator to analyze a new piece of text. This function resets
+ * the current iteration position to the beginning of the text.
+ * @param newText An iterator over the text to analyze.
+ */
+void
+RuleBasedBreakIterator::setText(const UnicodeString& newText) {
+ UErrorCode status = U_ZERO_ERROR;
+ reset();
+ fText = utext_openConstUnicodeString(fText, &newText, &status);
+
+ // Set up a character iterator on the string.
+ // Needed in case someone calls getText().
+ // Can not, unfortunately, do this lazily on the (probably never)
+ // call to getText(), because getText is const.
+ if (fSCharIter == NULL) {
+ fSCharIter = new StringCharacterIterator(newText);
+ } else {
+ fSCharIter->setText(newText);
+ }
+
+ if (fCharIter!=fSCharIter && fCharIter!=fDCharIter) {
+ // old fCharIter was adopted from the outside. Delete it.
+ delete fCharIter;
+ }
+ fCharIter = fSCharIter;
+
+ this->first();
+}
+
+
+
+/**
+ * Sets the current iteration position to the beginning of the text.
+ * @return The offset of the beginning of the text.
+ */
+int32_t RuleBasedBreakIterator::first(void) {
+ reset();
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ //if (fText == NULL)
+ // return BreakIterator::DONE;
+
+ utext_setNativeIndex(fText, 0);
+ return 0;
+}
+
+/**
+ * Sets the current iteration position to the end of the text.
+ * @return The text's past-the-end offset.
+ */
+int32_t RuleBasedBreakIterator::last(void) {
+ reset();
+ if (fText == NULL) {
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ return BreakIterator::DONE;
+ }
+
+ fLastStatusIndexValid = FALSE;
+ int32_t pos = (int32_t)utext_nativeLength(fText);
+ utext_setNativeIndex(fText, pos);
+ return pos;
+}
+
+/**
+ * Advances the iterator either forward or backward the specified number of steps.
+ * Negative values move backward, and positive values move forward. This is
+ * equivalent to repeatedly calling next() or previous().
+ * @param n The number of steps to move. The sign indicates the direction
+ * (negative is backwards, and positive is forwards).
+ * @return The character offset of the boundary position n boundaries away from
+ * the current one.
+ */
+int32_t RuleBasedBreakIterator::next(int32_t n) {
+ int32_t result = current();
+ while (n > 0) {
+ result = next();
+ --n;
+ }
+ while (n < 0) {
+ result = previous();
+ ++n;
+ }
+ return result;
+}
+
+/**
+ * Advances the iterator to the next boundary position.
+ * @return The position of the first boundary after this one.
+ */
+int32_t RuleBasedBreakIterator::next(void) {
+ // if we have cached break positions and we're still in the range
+ // covered by them, just move one step forward in the cache
+ if (fCachedBreakPositions != NULL) {
+ if (fPositionInCache < fNumCachedBreakPositions - 1) {
+ ++fPositionInCache;
+ int32_t pos = fCachedBreakPositions[fPositionInCache];
+ utext_setNativeIndex(fText, pos);
+ return pos;
+ }
+ else {
+ reset();
+ }
+ }
+
+ int32_t startPos = current();
+ int32_t result = handleNext(fData->fForwardTable);
+ if (fDictionaryCharCount > 0) {
+ result = checkDictionary(startPos, result, FALSE);
+ }
+ return result;
+}
+
+/**
+ * Advances the iterator backwards, to the last boundary preceding this one.
+ * @return The position of the last boundary position preceding this one.
+ */
+int32_t RuleBasedBreakIterator::previous(void) {
+ int32_t result;
+ int32_t startPos;
+
+ // if we have cached break positions and we're still in the range
+ // covered by them, just move one step backward in the cache
+ if (fCachedBreakPositions != NULL) {
+ if (fPositionInCache > 0) {
+ --fPositionInCache;
+ // If we're at the beginning of the cache, need to reevaluate the
+ // rule status
+ if (fPositionInCache <= 0) {
+ fLastStatusIndexValid = FALSE;
+ }
+ int32_t pos = fCachedBreakPositions[fPositionInCache];
+ utext_setNativeIndex(fText, pos);
+ return pos;
+ }
+ else {
+ reset();
+ }
+ }
+
+ // if we're already sitting at the beginning of the text, return DONE
+ if (fText == NULL || (startPos = current()) == 0) {
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ return BreakIterator::DONE;
+ }
+
+ if (fData->fSafeRevTable != NULL || fData->fSafeFwdTable != NULL) {
+ result = handlePrevious(fData->fReverseTable);
+ if (fDictionaryCharCount > 0) {
+ result = checkDictionary(result, startPos, TRUE);
+ }
+ return result;
+ }
+
+ // old rule syntax
+ // set things up. handlePrevious() will back us up to some valid
+ // break position before the current position (we back our internal
+ // iterator up one step to prevent handlePrevious() from returning
+ // the current position), but not necessarily the last one before
+
+ // where we started
+
+ int32_t start = current();
+
+ UTEXT_PREVIOUS32(fText);
+ int32_t lastResult = handlePrevious(fData->fReverseTable);
+ if (lastResult == UBRK_DONE) {
+ lastResult = 0;
+ utext_setNativeIndex(fText, 0);
+ }
+ result = lastResult;
+ int32_t lastTag = 0;
+ UBool breakTagValid = FALSE;
+
+ // iterate forward from the known break position until we pass our
+ // starting point. The last break position before the starting
+ // point is our return value
+
+ for (;;) {
+ result = next();
+ if (result == BreakIterator::DONE || result >= start) {
+ break;
+ }
+ lastResult = result;
+ lastTag = fLastRuleStatusIndex;
+ breakTagValid = TRUE;
+ }
+
+ // fLastBreakTag wants to have the value for section of text preceding
+ // the result position that we are to return (in lastResult.) If
+ // the backwards rules overshot and the above loop had to do two or more
+ // next()s to move up to the desired return position, we will have a valid
+ // tag value. But, if handlePrevious() took us to exactly the correct result positon,
+ // we wont have a tag value for that position, which is only set by handleNext().
+
+ // set the current iteration position to be the last break position
+ // before where we started, and then return that value
+ utext_setNativeIndex(fText, lastResult);
+ fLastRuleStatusIndex = lastTag; // for use by getRuleStatus()
+ fLastStatusIndexValid = breakTagValid;
+
+ // No need to check the dictionary; it will have been handled by
+ // next()
+
+ return lastResult;
+}
+
+/**
+ * Sets the iterator to refer to the first boundary position following
+ * the specified position.
+ * @offset The position from which to begin searching for a break position.
+ * @return The position of the first break after the current position.
+ */
+int32_t RuleBasedBreakIterator::following(int32_t offset) {
+ // if we have cached break positions and offset is in the range
+ // covered by them, use them
+ // TODO: could use binary search
+ // TODO: what if offset is outside range, but break is not?
+ if (fCachedBreakPositions != NULL) {
+ if (offset >= fCachedBreakPositions[0]
+ && offset < fCachedBreakPositions[fNumCachedBreakPositions - 1]) {
+ fPositionInCache = 0;
+ // We are guaranteed not to leave the array due to range test above
+ while (offset >= fCachedBreakPositions[fPositionInCache]) {
+ ++fPositionInCache;
+ }
+ int32_t pos = fCachedBreakPositions[fPositionInCache];
+ utext_setNativeIndex(fText, pos);
+ return pos;
+ }
+ else {
+ reset();
+ }
+ }
+
+ // if the offset passed in is already past the end of the text,
+ // just return DONE; if it's before the beginning, return the
+ // text's starting offset
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ if (fText == NULL || offset >= utext_nativeLength(fText)) {
+ last();
+ return next();
+ }
+ else if (offset < 0) {
+ return first();
+ }
+
+ // otherwise, set our internal iteration position (temporarily)
+ // to the position passed in. If this is the _beginning_ position,
+ // then we can just use next() to get our return value
+
+ int32_t result = 0;
+
+ if (fData->fSafeRevTable != NULL) {
+ // new rule syntax
+ utext_setNativeIndex(fText, offset);
+ // move forward one codepoint to prepare for moving back to a
+ // safe point.
+ // this handles offset being between a supplementary character
+ UTEXT_NEXT32(fText);
+ // handlePrevious will move most of the time to < 1 boundary away
+ handlePrevious(fData->fSafeRevTable);
+ int32_t result = next();
+ while (result <= offset) {
+ result = next();
+ }
+ return result;
+ }
+ if (fData->fSafeFwdTable != NULL) {
+ // backup plan if forward safe table is not available
+ utext_setNativeIndex(fText, offset);
+ UTEXT_PREVIOUS32(fText);
+ // handle next will give result >= offset
+ handleNext(fData->fSafeFwdTable);
+ // previous will give result 0 or 1 boundary away from offset,
+ // most of the time
+ // we have to
+ int32_t oldresult = previous();
+ while (oldresult > offset) {
+ int32_t result = previous();
+ if (result <= offset) {
+ return oldresult;
+ }
+ oldresult = result;
+ }
+ int32_t result = next();
+ if (result <= offset) {
+ return next();
+ }
+ return result;
+ }
+ // otherwise, we have to sync up first. Use handlePrevious() to back
+ // up to a known break position before the specified position (if
+ // we can determine that the specified position is a break position,
+ // we don't back up at all). This may or may not be the last break
+ // position at or before our starting position. Advance forward
+ // from here until we've passed the starting position. The position
+ // we stop on will be the first break position after the specified one.
+ // old rule syntax
+
+ utext_setNativeIndex(fText, offset);
+ if (offset==0 ||
+ offset==1 && utext_getNativeIndex(fText)==0) {
+ return next();
+ }
+ result = previous();
+
+ while (result != BreakIterator::DONE && result <= offset) {
+ result = next();
+ }
+
+ return result;
+}
+
+/**
+ * Sets the iterator to refer to the last boundary position before the
+ * specified position.
+ * @offset The position to begin searching for a break from.
+ * @return The position of the last boundary before the starting position.
+ */
+int32_t RuleBasedBreakIterator::preceding(int32_t offset) {
+ // if we have cached break positions and offset is in the range
+ // covered by them, use them
+ if (fCachedBreakPositions != NULL) {
+ // TODO: binary search?
+ // TODO: What if offset is outside range, but break is not?
+ if (offset > fCachedBreakPositions[0]
+ && offset <= fCachedBreakPositions[fNumCachedBreakPositions - 1]) {
+ fPositionInCache = 0;
+ while (fPositionInCache < fNumCachedBreakPositions
+ && offset > fCachedBreakPositions[fPositionInCache])
+ ++fPositionInCache;
+ --fPositionInCache;
+ // If we're at the beginning of the cache, need to reevaluate the
+ // rule status
+ if (fPositionInCache <= 0) {
+ fLastStatusIndexValid = FALSE;
+ }
+ utext_setNativeIndex(fText, fCachedBreakPositions[fPositionInCache]);
+ return fCachedBreakPositions[fPositionInCache];
+ }
+ else {
+ reset();
+ }
+ }
+
+ // if the offset passed in is already past the end of the text,
+ // just return DONE; if it's before the beginning, return the
+ // text's starting offset
+ if (fText == NULL || offset > utext_nativeLength(fText)) {
+ // return BreakIterator::DONE;
+ return last();
+ }
+ else if (offset < 0) {
+ return first();
+ }
+
+ // if we start by updating the current iteration position to the
+ // position specified by the caller, we can just use previous()
+ // to carry out this operation
+
+ if (fData->fSafeFwdTable != NULL) {
+ // new rule syntax
+ utext_setNativeIndex(fText, offset);
+ int32_t newOffset = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ if (newOffset != offset) {
+ // Will come here if specified offset was not a code point boundary AND
+ // the underlying implmentation is using UText, which snaps any non-code-point-boundary
+ // indices to the containing code point.
+ // For breakitereator::preceding only, these non-code-point indices need to be moved
+ // up to refer to the following codepoint.
+ UTEXT_NEXT32(fText);
+ offset = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ }
+
+ // TODO: (synwee) would it be better to just check for being in the middle of a surrogate pair,
+ // rather than adjusting the position unconditionally?
+ // (Change would interact with safe rules.)
+ // TODO: change RBBI behavior for off-boundary indices to match that of UText?
+ // affects only preceding(), seems cleaner, but is slightly different.
+ UTEXT_PREVIOUS32(fText);
+ handleNext(fData->fSafeFwdTable);
+ int32_t result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ while (result >= offset) {
+ result = previous();
+ }
+ return result;
+ }
+ if (fData->fSafeRevTable != NULL) {
+ // backup plan if forward safe table is not available
+ // TODO: check whether this path can be discarded
+ // It's probably OK to say that rules must supply both safe tables
+ // if they use safe tables at all. We have certainly never described
+ // to anyone how to work with just one safe table.
+ utext_setNativeIndex(fText, offset);
+ UTEXT_NEXT32(fText);
+
+ // handle previous will give result <= offset
+ handlePrevious(fData->fSafeRevTable);
+
+ // next will give result 0 or 1 boundary away from offset,
+ // most of the time
+ // we have to
+ int32_t oldresult = next();
+ while (oldresult < offset) {
+ int32_t result = next();
+ if (result >= offset) {
+ return oldresult;
+ }
+ oldresult = result;
+ }
+ int32_t result = previous();
+ if (result >= offset) {
+ return previous();
+ }
+ return result;
+ }
+
+ // old rule syntax
+ utext_setNativeIndex(fText, offset);
+ return previous();
+}
+
+/**
+ * Returns true if the specfied position is a boundary position. As a side
+ * effect, leaves the iterator pointing to the first boundary position at
+ * or after "offset".
+ * @param offset the offset to check.
+ * @return True if "offset" is a boundary position.
+ */
+UBool RuleBasedBreakIterator::isBoundary(int32_t offset) {
+ // the beginning index of the iterator is always a boundary position by definition
+ if (offset == 0) {
+ first(); // For side effects on current position, tag values.
+ return TRUE;
+ }
+
+ if (offset == (int32_t)utext_nativeLength(fText)) {
+ last(); // For side effects on current position, tag values.
+ return TRUE;
+ }
+
+ // out-of-range indexes are never boundary positions
+ if (offset < 0) {
+ first(); // For side effects on current position, tag values.
+ return FALSE;
+ }
+
+ if (offset > utext_nativeLength(fText)) {
+ last(); // For side effects on current position, tag values.
+ return FALSE;
+ }
+
+ // otherwise, we can use following() on the position before the specified
+ // one and return true if the position we get back is the one the user
+ // specified
+ utext_previous32From(fText, offset);
+ int32_t backOne = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ UBool result = following(backOne) == offset;
+ return result;
+}
+
+/**
+ * Returns the current iteration position.
+ * @return The current iteration position.
+ */
+int32_t RuleBasedBreakIterator::current(void) const {
+ int32_t pos = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ return pos;
+}
+
+//=======================================================================
+// implementation
+//=======================================================================
+
+//
+// RBBIRunMode - the state machine runs an extra iteration at the beginning and end
+// of user text. A variable with this enum type keeps track of where we
+// are. The state machine only fetches user input while in the RUN mode.
+//
+enum RBBIRunMode {
+ RBBI_START, // state machine processing is before first char of input
+ RBBI_RUN, // state machine processing is in the user text
+ RBBI_END // state machine processing is after end of user text.
+};
+
+
+//-----------------------------------------------------------------------------------
+//
+// handleNext(stateTable)
+// This method is the actual implementation of the rbbi next() method.
+// This method initializes the state machine to state 1
+// and advances through the text character by character until we reach the end
+// of the text or the state machine transitions to state 0. We update our return
+// value every time the state machine passes through an accepting state.
+//
+//-----------------------------------------------------------------------------------
+int32_t RuleBasedBreakIterator::handleNext(const RBBIStateTable *statetable) {
+ int32_t state;
+ int16_t category = 0;
+ RBBIRunMode mode;
+
+ RBBIStateTableRow *row;
+ UChar32 c;
+ int32_t lookaheadStatus = 0;
+ int32_t lookaheadTagIdx = 0;
+ int32_t result = 0;
+ int32_t initialPosition = 0;
+ int32_t lookaheadResult = 0;
+ UBool lookAheadHardBreak = (statetable->fFlags & RBBI_LOOKAHEAD_HARD_BREAK) != 0;
+ const char *tableData = statetable->fTableData;
+ uint32_t tableRowLen = statetable->fRowLen;
+
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPuts("Handle Next pos char state category");
+ }
+ #endif
+
+ // No matter what, handleNext alway correctly sets the break tag value.
+ fLastStatusIndexValid = TRUE;
+ fLastRuleStatusIndex = 0;
+
+ // if we're already at the end of the text, return DONE.
+ initialPosition = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ result = initialPosition;
+ c = UTEXT_NEXT32(fText);
+ if (fData == NULL || c==U_SENTINEL) {
+ return BreakIterator::DONE;
+ }
+
+ // Set the initial state for the state machine
+ state = START_STATE;
+ row = (RBBIStateTableRow *)
+ //(statetable->fTableData + (statetable->fRowLen * state));
+ (tableData + tableRowLen * state);
+
+
+ mode = RBBI_RUN;
+ if (statetable->fFlags & RBBI_BOF_REQUIRED) {
+ category = 2;
+ mode = RBBI_START;
+ }
+
+
+ // loop until we reach the end of the text or transition to state 0
+ //
+ for (;;) {
+ if (c == U_SENTINEL) {
+ // Reached end of input string.
+ if (mode == RBBI_END) {
+ // We have already run the loop one last time with the
+ // character set to the psueudo {eof} value. Now it is time
+ // to unconditionally bail out.
+ if (lookaheadResult > result) {
+ // We ran off the end of the string with a pending look-ahead match.
+ // Treat this as if the look-ahead condition had been met, and return
+ // the match at the / position from the look-ahead rule.
+ result = lookaheadResult;
+ fLastRuleStatusIndex = lookaheadTagIdx;
+ lookaheadStatus = 0;
+ }
+ break;
+ }
+ // Run the loop one last time with the fake end-of-input character category.
+ mode = RBBI_END;
+ category = 1;
+ }
+
+ //
+ // Get the char category. An incoming category of 1 or 2 means that
+ // we are preset for doing the beginning or end of input, and
+ // that we shouldn't get a category from an actual text input character.
+ //
+ if (mode == RBBI_RUN) {
+ // look up the current character's character category, which tells us
+ // which column in the state table to look at.
+ // Note: the 16 in UTRIE_GET16 refers to the size of the data being returned,
+ // not the size of the character going in, which is a UChar32.
+ //
+ UTRIE_GET16(&fData->fTrie, c, category);
+
+ // Check the dictionary bit in the character's category.
+ // Counter is only used by dictionary based iterators (subclasses).
+ // Chars that need to be handled by a dictionary have a flag bit set
+ // in their category values.
+ //
+ if ((category & 0x4000) != 0) {
+ fDictionaryCharCount++;
+ // And off the dictionary flag bit.
+ category &= ~0x4000;
+ }
+ }
+
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPrintf(" %4d ", utext_getNativeIndex(fText));
+ if (0x20<=c && c<0x7f) {
+ RBBIDebugPrintf("\"%c\" ", c);
+ } else {
+ RBBIDebugPrintf("%5x ", c);
+ }
+ RBBIDebugPrintf("%3d %3d\n", state, category);
+ }
+ #endif
+
+ // State Transition - move machine to its next state
+ //
+ state = row->fNextState[category];
+ row = (RBBIStateTableRow *)
+ // (statetable->fTableData + (statetable->fRowLen * state));
+ (tableData + tableRowLen * state);
+
+
+ if (row->fAccepting == -1) {
+ // Match found, common case.
+ if (mode != RBBI_START) {
+ result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ }
+ fLastRuleStatusIndex = row->fTagIdx; // Remember the break status (tag) values.
+ }
+
+ if (row->fLookAhead != 0) {
+ if (lookaheadStatus != 0
+ && row->fAccepting == lookaheadStatus) {
+ // Lookahead match is completed.
+ result = lookaheadResult;
+ fLastRuleStatusIndex = lookaheadTagIdx;
+ lookaheadStatus = 0;
+ // TODO: make a standalone hard break in a rule work.
+ if (lookAheadHardBreak) {
+ UTEXT_SETNATIVEINDEX(fText, result);
+ return result;
+ }
+ // Look-ahead completed, but other rules may match further. Continue on
+ // TODO: junk this feature? I don't think it's used anywhwere.
+ goto continueOn;
+ }
+
+ int32_t r = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ lookaheadResult = r;
+ lookaheadStatus = row->fLookAhead;
+ lookaheadTagIdx = row->fTagIdx;
+ goto continueOn;
+ }
+
+
+ if (row->fAccepting != 0) {
+ // Because this is an accepting state, any in-progress look-ahead match
+ // is no longer relavant. Clear out the pending lookahead status.
+ lookaheadStatus = 0; // clear out any pending look-ahead match.
+ }
+
+continueOn:
+ if (state == STOP_STATE) {
+ // This is the normal exit from the lookup state machine.
+ // We have advanced through the string until it is certain that no
+ // longer match is possible, no matter what characters follow.
+ break;
+ }
+
+ // Advance to the next character.
+ // If this is a beginning-of-input loop iteration, don't advance
+ // the input position. The next iteration will be processing the
+ // first real input character.
+ if (mode == RBBI_RUN) {
+ c = UTEXT_NEXT32(fText);
+ } else {
+ if (mode == RBBI_START) {
+ mode = RBBI_RUN;
+ }
+ }
+
+
+ }
+
+ // The state machine is done. Check whether it found a match...
+
+ // If the iterator failed to advance in the match engine, force it ahead by one.
+ // (This really indicates a defect in the break rules. They should always match
+ // at least one character.)
+ if (result == initialPosition) {
+ UTEXT_SETNATIVEINDEX(fText, initialPosition);
+ UTEXT_NEXT32(fText);
+ result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ }
+
+ // Leave the iterator at our result position.
+ UTEXT_SETNATIVEINDEX(fText, result);
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPrintf("result = %d\n\n", result);
+ }
+ #endif
+ return result;
+}
+
+
+
+//-----------------------------------------------------------------------------------
+//
+// handlePrevious()
+//
+// Iterate backwards, according to the logic of the reverse rules.
+// This version handles the exact style backwards rules.
+//
+// The logic of this function is very similar to handleNext(), above.
+//
+//-----------------------------------------------------------------------------------
+int32_t RuleBasedBreakIterator::handlePrevious(const RBBIStateTable *statetable) {
+ int32_t state;
+ int16_t category = 0;
+ RBBIRunMode mode;
+ RBBIStateTableRow *row;
+ UChar32 c;
+ int32_t lookaheadStatus = 0;
+ int32_t result = 0;
+ int32_t initialPosition = 0;
+ int32_t lookaheadResult = 0;
+ UBool lookAheadHardBreak = (statetable->fFlags & RBBI_LOOKAHEAD_HARD_BREAK) != 0;
+
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPuts("Handle Previous pos char state category");
+ }
+ #endif
+
+ // handlePrevious() never gets the rule status.
+ // Flag the status as invalid; if the user ever asks for status, we will need
+ // to back up, then re-find the break position using handleNext(), which does
+ // get the status value.
+ fLastStatusIndexValid = FALSE;
+ fLastRuleStatusIndex = 0;
+
+ // if we're already at the start of the text, return DONE.
+ if (fText == NULL || fData == NULL || UTEXT_GETNATIVEINDEX(fText)==0) {
+ return BreakIterator::DONE;
+ }
+
+ // Set up the starting char.
+ initialPosition = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ result = initialPosition;
+ c = UTEXT_PREVIOUS32(fText);
+
+ // Set the initial state for the state machine
+ state = START_STATE;
+ row = (RBBIStateTableRow *)
+ (statetable->fTableData + (statetable->fRowLen * state));
+ category = 3;
+ mode = RBBI_RUN;
+ if (statetable->fFlags & RBBI_BOF_REQUIRED) {
+ category = 2;
+ mode = RBBI_START;
+ }
+
+
+ // loop until we reach the start of the text or transition to state 0
+ //
+ for (;;) {
+ if (c == U_SENTINEL) {
+ // Reached end of input string.
+ if (mode == RBBI_END ||
+ *(int32_t *)fData->fHeader->fFormatVersion == 1 ) {
+ // We have already run the loop one last time with the
+ // character set to the psueudo {eof} value. Now it is time
+ // to unconditionally bail out.
+ // (Or we have an old format binary rule file that does not support {eof}.)
+ if (lookaheadResult < result) {
+ // We ran off the end of the string with a pending look-ahead match.
+ // Treat this as if the look-ahead condition had been met, and return
+ // the match at the / position from the look-ahead rule.
+ result = lookaheadResult;
+ lookaheadStatus = 0;
+ } else if (result == initialPosition) {
+ // Ran off start, no match found.
+ // move one index one (towards the start, since we are doing a previous())
+ UTEXT_SETNATIVEINDEX(fText, initialPosition);
+ UTEXT_PREVIOUS32(fText); // TODO: shouldn't be necessary. We're already at beginning. Check.
+ }
+ break;
+ }
+ // Run the loop one last time with the fake end-of-input character category.
+ mode = RBBI_END;
+ category = 1;
+ }
+
+ //
+ // Get the char category. An incoming category of 1 or 2 means that
+ // we are preset for doing the beginning or end of input, and
+ // that we shouldn't get a category from an actual text input character.
+ //
+ if (mode == RBBI_RUN) {
+ // look up the current character's character category, which tells us
+ // which column in the state table to look at.
+ // Note: the 16 in UTRIE_GET16 refers to the size of the data being returned,
+ // not the size of the character going in, which is a UChar32.
+ //
+ UTRIE_GET16(&fData->fTrie, c, category);
+
+ // Check the dictionary bit in the character's category.
+ // Counter is only used by dictionary based iterators (subclasses).
+ // Chars that need to be handled by a dictionary have a flag bit set
+ // in their category values.
+ //
+ if ((category & 0x4000) != 0) {
+ fDictionaryCharCount++;
+ // And off the dictionary flag bit.
+ category &= ~0x4000;
+ }
+ }
+
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPrintf(" %4d ", (int32_t)utext_getNativeIndex(fText));
+ if (0x20<=c && c<0x7f) {
+ RBBIDebugPrintf("\"%c\" ", c);
+ } else {
+ RBBIDebugPrintf("%5x ", c);
+ }
+ RBBIDebugPrintf("%3d %3d\n", state, category);
+ }
+ #endif
+
+ // State Transition - move machine to its next state
+ //
+ state = row->fNextState[category];
+ row = (RBBIStateTableRow *)
+ (statetable->fTableData + (statetable->fRowLen * state));
+
+ if (row->fAccepting == -1) {
+ // Match found, common case.
+ result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ }
+
+ if (row->fLookAhead != 0) {
+ if (lookaheadStatus != 0
+ && row->fAccepting == lookaheadStatus) {
+ // Lookahead match is completed.
+ result = lookaheadResult;
+ lookaheadStatus = 0;
+ // TODO: make a standalone hard break in a rule work.
+ if (lookAheadHardBreak) {
+ UTEXT_SETNATIVEINDEX(fText, result);
+ return result;
+ }
+ // Look-ahead completed, but other rules may match further. Continue on
+ // TODO: junk this feature? I don't think it's used anywhwere.
+ goto continueOn;
+ }
+
+ int32_t r = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ lookaheadResult = r;
+ lookaheadStatus = row->fLookAhead;
+ goto continueOn;
+ }
+
+
+ if (row->fAccepting != 0) {
+ // Because this is an accepting state, any in-progress look-ahead match
+ // is no longer relavant. Clear out the pending lookahead status.
+ lookaheadStatus = 0;
+ }
+
+continueOn:
+ if (state == STOP_STATE) {
+ // This is the normal exit from the lookup state machine.
+ // We have advanced through the string until it is certain that no
+ // longer match is possible, no matter what characters follow.
+ break;
+ }
+
+ // Move (backwards) to the next character to process.
+ // If this is a beginning-of-input loop iteration, don't advance
+ // the input position. The next iteration will be processing the
+ // first real input character.
+ if (mode == RBBI_RUN) {
+ c = UTEXT_PREVIOUS32(fText);
+ } else {
+ if (mode == RBBI_START) {
+ mode = RBBI_RUN;
+ }
+ }
+ }
+
+ // The state machine is done. Check whether it found a match...
+
+ // If the iterator failed to advance in the match engine, force it ahead by one.
+ // (This really indicates a defect in the break rules. They should always match
+ // at least one character.)
+ if (result == initialPosition) {
+ UTEXT_SETNATIVEINDEX(fText, initialPosition);
+ UTEXT_PREVIOUS32(fText);
+ result = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ }
+
+ // Leave the iterator at our result position.
+ UTEXT_SETNATIVEINDEX(fText, result);
+ #ifdef RBBI_DEBUG
+ if (fTrace) {
+ RBBIDebugPrintf("result = %d\n\n", result);
+ }
+ #endif
+ return result;
+}
+
+
+void
+RuleBasedBreakIterator::reset()
+{
+ if (fCachedBreakPositions) {
+ uprv_free(fCachedBreakPositions);
+ }
+ fCachedBreakPositions = NULL;
+ fNumCachedBreakPositions = 0;
+ fDictionaryCharCount = 0;
+ fPositionInCache = 0;
+}
+
+
+
+//-------------------------------------------------------------------------------
+//
+// getRuleStatus() Return the break rule tag associated with the current
+// iterator position. If the iterator arrived at its current
+// position by iterating forwards, the value will have been
+// cached by the handleNext() function.
+//
+// If no cached status value is available, the status is
+// found by doing a previous() followed by a next(), which
+// leaves the iterator where it started, and computes the
+// status while doing the next().
+//
+//-------------------------------------------------------------------------------
+void RuleBasedBreakIterator::makeRuleStatusValid() {
+ if (fLastStatusIndexValid == FALSE) {
+ // No cached status is available.
+ if (fText == NULL || current() == 0) {
+ // At start of text, or there is no text. Status is always zero.
+ fLastRuleStatusIndex = 0;
+ fLastStatusIndexValid = TRUE;
+ } else {
+ // Not at start of text. Find status the tedious way.
+ int32_t pa = current();
+ previous();
+ if (fNumCachedBreakPositions > 0) {
+ reset(); // Blow off the dictionary cache
+ }
+ int32_t pb = next();
+ if (pa != pb) {
+ // note: the if (pa != pb) test is here only to eliminate warnings for
+ // unused local variables on gcc. Logically, it isn't needed.
+ U_ASSERT(pa == pb);
+ }
+ }
+ }
+ U_ASSERT(fLastRuleStatusIndex >= 0 && fLastRuleStatusIndex < fData->fStatusMaxIdx);
+}
+
+
+int32_t RuleBasedBreakIterator::getRuleStatus() const {
+ RuleBasedBreakIterator *nonConstThis = (RuleBasedBreakIterator *)this;
+ nonConstThis->makeRuleStatusValid();
+
+ // fLastRuleStatusIndex indexes to the start of the appropriate status record
+ // (the number of status values.)
+ // This function returns the last (largest) of the array of status values.
+ int32_t idx = fLastRuleStatusIndex + fData->fRuleStatusTable[fLastRuleStatusIndex];
+ int32_t tagVal = fData->fRuleStatusTable[idx];
+
+ return tagVal;
+}
+
+
+
+
+int32_t RuleBasedBreakIterator::getRuleStatusVec(
+ int32_t *fillInVec, int32_t capacity, UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ RuleBasedBreakIterator *nonConstThis = (RuleBasedBreakIterator *)this;
+ nonConstThis->makeRuleStatusValid();
+ int32_t numVals = fData->fRuleStatusTable[fLastRuleStatusIndex];
+ int32_t numValsToCopy = numVals;
+ if (numVals > capacity) {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ numValsToCopy = capacity;
+ }
+ int i;
+ for (i=0; ifRuleStatusTable[fLastRuleStatusIndex + i + 1];
+ }
+ return numVals;
+}
+
+
+
+//-------------------------------------------------------------------------------
+//
+// getBinaryRules Access to the compiled form of the rules,
+// for use by build system tools that save the data
+// for standard iterator types.
+//
+//-------------------------------------------------------------------------------
+const uint8_t *RuleBasedBreakIterator::getBinaryRules(uint32_t &length) {
+ const uint8_t *retPtr = NULL;
+ length = 0;
+
+ if (fData != NULL) {
+ retPtr = (const uint8_t *)fData->fHeader;
+ length = fData->fHeader->fLength;
+ }
+ return retPtr;
+}
+
+
+
+
+//-------------------------------------------------------------------------------
+//
+// BufferClone TODO: In my (Andy) opinion, this function should be deprecated.
+// Saving one heap allocation isn't worth the trouble.
+// Cloning shouldn't be done in tight loops, and
+// making the clone copy involves other heap operations anyway.
+// And the application code for correctly dealing with buffer
+// size problems and the eventual object destruction is ugly.
+//
+//-------------------------------------------------------------------------------
+BreakIterator * RuleBasedBreakIterator::createBufferClone(void *stackBuffer,
+ int32_t &bufferSize,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)){
+ return NULL;
+ }
+
+ //
+ // If user buffer size is zero this is a preflight operation to
+ // obtain the needed buffer size, allowing for worst case misalignment.
+ //
+ if (bufferSize == 0) {
+ bufferSize = sizeof(RuleBasedBreakIterator) + U_ALIGNMENT_OFFSET_UP(0);
+ return NULL;
+ }
+
+
+ //
+ // Check the alignment and size of the user supplied buffer.
+ // Allocate heap memory if the user supplied memory is insufficient.
+ //
+ char *buf = (char *)stackBuffer;
+ uint32_t s = bufferSize;
+
+ if (stackBuffer == NULL) {
+ s = 0; // Ignore size, force allocation if user didn't give us a buffer.
+ }
+ if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
+ uint32_t offsetUp = (uint32_t)U_ALIGNMENT_OFFSET_UP(buf);
+ s -= offsetUp;
+ buf += offsetUp;
+ }
+ if (s < sizeof(RuleBasedBreakIterator)) {
+ // Not enough room in the caller-supplied buffer.
+ // Do a plain-vanilla heap based clone and return that, along with
+ // a warning that the clone was allocated.
+ RuleBasedBreakIterator *clonedBI = new RuleBasedBreakIterator(*this);
+ if (clonedBI == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ status = U_SAFECLONE_ALLOCATED_WARNING;
+ }
+ return clonedBI;
+ }
+
+ //
+ // Clone the source BI into the caller-supplied buffer.
+ // TODO: using an overloaded operator new to directly initialize the
+ // copy in the user's buffer would be better, but it doesn't seem
+ // to get along with namespaces. Investigate why.
+ //
+ // The memcpy is only safe with an empty (default constructed)
+ // break iterator. Use on others can screw up reference counts
+ // to data. memcpy-ing objects is not really a good idea...
+ //
+ RuleBasedBreakIterator localIter; // Empty break iterator, source for memcpy
+ RuleBasedBreakIterator *clone = (RuleBasedBreakIterator *)buf;
+ uprv_memcpy(clone, &localIter, sizeof(RuleBasedBreakIterator)); // init C++ gorp, BreakIterator base class part
+ clone->init(); // Init RuleBasedBreakIterator part, (user default constructor)
+ *clone = *this; // clone = the real BI we want.
+ clone->fBufferClone = TRUE; // Flag to prevent deleting storage on close (From C code)
+
+ return clone;
+}
+
+
+//-------------------------------------------------------------------------------
+//
+// isDictionaryChar Return true if the category lookup for this char
+// indicates that it is in the set of dictionary lookup
+// chars.
+//
+// This function is intended for use by dictionary based
+// break iterators.
+//
+//-------------------------------------------------------------------------------
+/*UBool RuleBasedBreakIterator::isDictionaryChar(UChar32 c) {
+ if (fData == NULL) {
+ return FALSE;
+ }
+ uint16_t category;
+ UTRIE_GET16(&fData->fTrie, c, category);
+ return (category & 0x4000) != 0;
+}*/
+
+
+//-------------------------------------------------------------------------------
+//
+// checkDictionary This function handles all processing of characters in
+// the "dictionary" set. It will determine the appropriate
+// course of action, and possibly set up a cache in the
+// process.
+//
+//-------------------------------------------------------------------------------
+int32_t RuleBasedBreakIterator::checkDictionary(int32_t startPos,
+ int32_t endPos,
+ UBool reverse) {
+ // Reset the old break cache first.
+ uint32_t dictionaryCount = fDictionaryCharCount;
+ reset();
+
+ if (dictionaryCount <= 1 || (endPos - startPos) <= 1) {
+ return (reverse ? startPos : endPos);
+ }
+
+ // Starting from the starting point, scan towards the proposed result,
+ // looking for the first dictionary character (which may be the one
+ // we're on, if we're starting in the middle of a range).
+ utext_setNativeIndex(fText, reverse ? endPos : startPos);
+ if (reverse) {
+ UTEXT_PREVIOUS32(fText);
+ }
+
+ int32_t rangeStart = startPos;
+ int32_t rangeEnd = endPos;
+
+ uint16_t category;
+ int32_t current;
+ UErrorCode status = U_ZERO_ERROR;
+ UStack breaks(status);
+ int32_t foundBreakCount = 0;
+ UChar32 c = utext_current32(fText);
+
+ UTRIE_GET16(&fData->fTrie, c, category);
+
+ // Is the character we're starting on a dictionary character? If so, we
+ // need to back up to include the entire run; otherwise the results of
+ // the break algorithm will differ depending on where we start. Since
+ // the result is cached and there is typically a non-dictionary break
+ // within a small number of words, there should be little performance impact.
+ if (category & 0x4000) {
+ if (reverse) {
+ do {
+ utext_next32(fText); // TODO: recast to work directly with postincrement.
+ c = utext_current32(fText);
+ UTRIE_GET16(&fData->fTrie, c, category);
+ } while (c != U_SENTINEL && (category & 0x4000));
+ // Back up to the last dictionary character
+ rangeEnd = (int32_t)UTEXT_GETNATIVEINDEX(fText);
+ if (c == U_SENTINEL) {
+ // c = fText->last32();
+ // TODO: why was this if needed?
+ c = UTEXT_PREVIOUS32(fText);
+ }
+ else {
+ c = UTEXT_PREVIOUS32(fText);
+ }
+ }
+ else {
+ do {
+ c = UTEXT_PREVIOUS32(fText);
+ UTRIE_GET16(&fData->fTrie, c, category);
+ }
+ while (c != U_SENTINEL && (category & 0x4000));
+ // Back up to the last dictionary character
+ if (c == U_SENTINEL) {
+ // c = fText->first32();
+ c = utext_current32(fText);
+ }
+ else {
+ utext_next32(fText);
+ c = utext_current32(fText);
+ }
+ rangeStart = (int32_t)UTEXT_GETNATIVEINDEX(fText);;
+ }
+ UTRIE_GET16(&fData->fTrie, c, category);
+ }
+
+ // Loop through the text, looking for ranges of dictionary characters.
+ // For each span, find the appropriate break engine, and ask it to find
+ // any breaks within the span.
+ // Note: we always do this in the forward direction, so that the break
+ // cache is built in the right order.
+ if (reverse) {
+ utext_setNativeIndex(fText, rangeStart);
+ c = utext_current32(fText);
+ UTRIE_GET16(&fData->fTrie, c, category);
+ }
+ while(U_SUCCESS(status)) {
+ while((current = (int32_t)UTEXT_GETNATIVEINDEX(fText)) < rangeEnd && (category & 0x4000) == 0) {
+ utext_next32(fText); // TODO: tweak for post-increment operation
+ c = utext_current32(fText);
+ UTRIE_GET16(&fData->fTrie, c, category);
+ }
+ if (current >= rangeEnd) {
+ break;
+ }
+
+ // We now have a dictionary character. Get the appropriate language object
+ // to deal with it.
+ const LanguageBreakEngine *lbe = getLanguageBreakEngine(c);
+
+ // Ask the language object if there are any breaks. It will leave the text
+ // pointer on the other side of its range, ready to search for the next one.
+ if (lbe != NULL) {
+ foundBreakCount += lbe->findBreaks(fText, rangeStart, rangeEnd, FALSE, fBreakType, breaks);
+ }
+
+ // Reload the loop variables for the next go-round
+ c = utext_current32(fText);
+ UTRIE_GET16(&fData->fTrie, c, category);
+ }
+
+ // If we found breaks, build a new break cache. The first and last entries must
+ // be the original starting and ending position.
+ if (foundBreakCount > 0) {
+ int32_t totalBreaks = foundBreakCount;
+ if (startPos < breaks.elementAti(0)) {
+ totalBreaks += 1;
+ }
+ if (endPos > breaks.peeki()) {
+ totalBreaks += 1;
+ }
+ fCachedBreakPositions = (int32_t *)uprv_malloc(totalBreaks * sizeof(int32_t));
+ if (fCachedBreakPositions != NULL) {
+ int32_t out = 0;
+ fNumCachedBreakPositions = totalBreaks;
+ if (startPos < breaks.elementAti(0)) {
+ fCachedBreakPositions[out++] = startPos;
+ }
+ for (int32_t i = 0; i < foundBreakCount; ++i) {
+ fCachedBreakPositions[out++] = breaks.elementAti(i);
+ }
+ if (endPos > fCachedBreakPositions[out-1]) {
+ fCachedBreakPositions[out] = endPos;
+ }
+ // If there are breaks, then by definition, we are replacing the original
+ // proposed break by one of the breaks we found. Use following() and
+ // preceding() to do the work. They should never recurse in this case.
+ if (reverse) {
+ return preceding(endPos - 1);
+ }
+ else {
+ return following(startPos);
+ }
+ }
+ // If the allocation failed, just fall through to the "no breaks found" case.
+ }
+
+ // If we get here, there were no language-based breaks. Set the text pointer
+ // to the original proposed break.
+ utext_setNativeIndex(fText, reverse ? startPos : endPos);
+ return (reverse ? startPos : endPos);
+}
+
+U_NAMESPACE_END
+
+// defined in ucln_cmn.h
+
+static U_NAMESPACE_QUALIFIER UStack *gLanguageBreakFactories = NULL;
+
+/**
+ * Release all static memory held by breakiterator.
+ */
+U_CDECL_BEGIN
+static UBool U_CALLCONV breakiterator_cleanup_dict(void) {
+ if (gLanguageBreakFactories) {
+ delete gLanguageBreakFactories;
+ gLanguageBreakFactories = NULL;
+ }
+ return TRUE;
+}
+U_CDECL_END
+
+U_CDECL_BEGIN
+static void U_CALLCONV _deleteFactory(void *obj) {
+ delete (U_NAMESPACE_QUALIFIER LanguageBreakFactory *) obj;
+}
+U_CDECL_END
+U_NAMESPACE_BEGIN
+
+static const LanguageBreakEngine*
+getLanguageBreakEngineFromFactory(UChar32 c, int32_t breakType)
+{
+ UBool needsInit;
+ UErrorCode status = U_ZERO_ERROR;
+ UMTX_CHECK(NULL, (UBool)(gLanguageBreakFactories == NULL), needsInit);
+
+ if (needsInit) {
+ UStack *factories = new UStack(_deleteFactory, NULL, status);
+ if (U_SUCCESS(status)) {
+ ICULanguageBreakFactory *builtIn = new ICULanguageBreakFactory(status);
+ factories->push(builtIn, status);
+#ifdef U_LOCAL_SERVICE_HOOK
+ LanguageBreakFactory *extra = (LanguageBreakFactory *)uprv_svc_hook("languageBreakFactory", &status);
+ if (extra != NULL) {
+ factories->push(extra, status);
+ }
+#endif
+ }
+ umtx_lock(NULL);
+ if (gLanguageBreakFactories == NULL) {
+ gLanguageBreakFactories = factories;
+ factories = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_BREAKITERATOR_DICT, breakiterator_cleanup_dict);
+ }
+ umtx_unlock(NULL);
+ delete factories;
+ }
+
+ if (gLanguageBreakFactories == NULL) {
+ return NULL;
+ }
+
+ int32_t i = gLanguageBreakFactories->size();
+ const LanguageBreakEngine *lbe = NULL;
+ while (--i >= 0) {
+ LanguageBreakFactory *factory = (LanguageBreakFactory *)(gLanguageBreakFactories->elementAt(i));
+ lbe = factory->getEngineFor(c, breakType);
+ if (lbe != NULL) {
+ break;
+ }
+ }
+ return lbe;
+}
+
+
+//-------------------------------------------------------------------------------
+//
+// getLanguageBreakEngine Find an appropriate LanguageBreakEngine for the
+// the characer c.
+//
+//-------------------------------------------------------------------------------
+const LanguageBreakEngine *
+RuleBasedBreakIterator::getLanguageBreakEngine(UChar32 c) {
+ const LanguageBreakEngine *lbe = NULL;
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (fLanguageBreakEngines == NULL) {
+ fLanguageBreakEngines = new UStack(status);
+ if (U_FAILURE(status)) {
+ delete fLanguageBreakEngines;
+ fLanguageBreakEngines = 0;
+ return NULL;
+ }
+ }
+
+ int32_t i = fLanguageBreakEngines->size();
+ while (--i >= 0) {
+ lbe = (const LanguageBreakEngine *)(fLanguageBreakEngines->elementAt(i));
+ if (lbe->handles(c, fBreakType)) {
+ return lbe;
+ }
+ }
+
+ // No existing dictionary took the character. See if a factory wants to
+ // give us a new LanguageBreakEngine for this character.
+ lbe = getLanguageBreakEngineFromFactory(c, fBreakType);
+
+ // If we got one, use it and push it on our stack.
+ if (lbe != NULL) {
+ fLanguageBreakEngines->push((void *)lbe, status);
+ // Even if we can't remember it, we can keep looking it up, so
+ // return it even if the push fails.
+ return lbe;
+ }
+
+ // No engine is forthcoming for this character. Add it to the
+ // reject set. Create the reject break engine if needed.
+ if (fUnhandledBreakEngine == NULL) {
+ fUnhandledBreakEngine = new UnhandledEngine(status);
+ if (U_SUCCESS(status) && fUnhandledBreakEngine == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ // Put it last so that scripts for which we have an engine get tried
+ // first.
+ fLanguageBreakEngines->insertElementAt(fUnhandledBreakEngine, 0, status);
+ // If we can't insert it, or creation failed, get rid of it
+ if (U_FAILURE(status)) {
+ delete fUnhandledBreakEngine;
+ fUnhandledBreakEngine = 0;
+ return NULL;
+ }
+ }
+
+ // Tell the reject engine about the character; at its discretion, it may
+ // add more than just the one character.
+ fUnhandledBreakEngine->handleCharacter(c, fBreakType);
+
+ return fUnhandledBreakEngine;
+}
+
+
+
+/*int32_t RuleBasedBreakIterator::getBreakType() const {
+ return fBreakType;
+}*/
+
+void RuleBasedBreakIterator::setBreakType(int32_t type) {
+ fBreakType = type;
+ reset();
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbicst.pl b/Build/source/libs/icu/icu-xetex/common/rbbicst.pl
new file mode 100755
index 00000000000..98b06cbc27d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbicst.pl
@@ -0,0 +1,453 @@
+#**************************************************************************
+# Copyright (C) 2002-2005 International Business Machines Corporation *
+# and others. All rights reserved. *
+#**************************************************************************
+#
+# rbbicst Compile the RBBI rule paser state table data into initialized C data.
+# Usage:
+# cd icu/source/common
+# perl rbbicst.pl < rbbirpt.txt > rbbirpt.h
+# perl rbbicst.pl -j < rbbirpt.txt > RBBIRuleParseTable.java
+#
+# The output file, rbbrpt.h, is included by some of the .cpp rbbi
+# implementation files. This perl script is NOT run as part
+# of a normal ICU build. It is run by hand when needed, and the
+# rbbirpt.h generated file is put back into cvs.
+#
+# See rbbirpt.txt for a description of the input format for this script.
+#
+
+if ($ARGV[0] eq "-j") {
+ $javaOutput = 1;
+ shift @ARGV;
+}
+
+
+$num_states = 1; # Always the state number for the line being compiled.
+$line_num = 0; # The line number in the input file.
+
+$states{"pop"} = 255; # Add the "pop" to the list of defined state names.
+ # This prevents any state from being labelled with "pop",
+ # and resolves references to "pop" in the next state field.
+
+line_loop: while (<>) {
+ chomp();
+ $line = $_;
+ @fields = split();
+ $line_num++;
+
+ # Remove # comments, which are any fields beginning with a #, plus all
+ # that follow on the line.
+ for ($i=0; $i<@fields; $i++) {
+ if ($fields[$i] =~ /^#/) {
+ @fields = @fields[0 .. $i-1];
+ last;
+ }
+ }
+ # ignore blank lines, and those with no fields left after stripping comments..
+ if (@fields == 0) {
+ next;
+ }
+
+ #
+ # State Label: handling.
+ # Does the first token end with a ":"? If so, it's the name of a state.
+ # Put in a hash, together with the current state number,
+ # so that we can later look up the number from the name.
+ #
+ if (@fields[0] =~ /.*:$/) {
+ $state_name = @fields[0];
+ $state_name =~ s/://; # strip off the colon from the state name.
+
+ if ($states{$state_name} != 0) {
+ print " rbbicst: at line $line-num duplicate definition of state $state_name\n";
+ }
+ $states{$state_name} = $num_states;
+ $stateNames[$num_states] = $state_name;
+
+ # if the label was the only thing on this line, go on to the next line,
+ # otherwise assume that a state definition is on the same line and fall through.
+ if (@fields == 1) {
+ next line_loop;
+ }
+ shift @fields; # shift off label field in preparation
+ # for handling the rest of the line.
+ }
+
+ #
+ # State Transition line.
+ # syntax is this,
+ # character [n] target-state [^push-state] [function-name]
+ # where
+ # [something] is an optional something
+ # character is either a single quoted character e.g. '['
+ # or a name of a character class, e.g. white_space
+ #
+
+ $state_line_num[$num_states] = $line_num; # remember line number with each state
+ # so we can make better error messages later.
+ #
+ # First field, character class or literal character for this transition.
+ #
+ if ($fields[0] =~ /^'.'$/) {
+ # We've got a quoted literal character.
+ $state_literal_chars[$num_states] = $fields[0];
+ $state_literal_chars[$num_states] =~ s/'//g;
+ } else {
+ # We've got the name of a character class.
+ $state_char_class[$num_states] = $fields[0];
+ if ($fields[0] =~ /[\W]/) {
+ print " rbbicsts: at line $line_num, bad character literal or character class name.\n";
+ print " scanning $fields[0]\n";
+ exit(-1);
+ }
+ }
+ shift @fields;
+
+ #
+ # do the 'n' flag
+ #
+ $state_flag[$num_states] = $javaOutput? "false" : "FALSE";
+ if ($fields[0] eq "n") {
+ $state_flag[$num_states] = $javaOutput? "true": "TRUE";
+ shift @fields;
+ }
+
+ #
+ # do the destination state.
+ #
+ $state_dest_state[$num_states] = $fields[0];
+ if ($fields[0] eq "") {
+ print " rbbicsts: at line $line_num, destination state missing.\n";
+ exit(-1);
+ }
+ shift @fields;
+
+ #
+ # do the push state, if present.
+ #
+ if ($fields[0] =~ /^\^/) {
+ $fields[0] =~ s/^\^//;
+ $state_push_state[$num_states] = $fields[0];
+ if ($fields[0] eq "" ) {
+ print " rbbicsts: at line $line_num, expected state after ^ (no spaces).\n";
+ exit(-1);
+ }
+ shift @fields;
+ }
+
+ #
+ # Lastly, do the optional action name.
+ #
+ if ($fields[0] ne "") {
+ $state_func_name[$num_states] = $fields[0];
+ shift @fields;
+ }
+
+ #
+ # There should be no fields left on the line at this point.
+ #
+ if (@fields > 0) {
+ print " rbbicsts: at line $line_num, unexpected extra stuff on input line.\n";
+ print " scanning $fields[0]\n";
+ }
+ $num_states++;
+}
+
+#
+# We've read in the whole file, now go back and output the
+# C source code for the state transition table.
+#
+# We read all states first, before writing anything, so that the state numbers
+# for the destination states are all available to be written.
+#
+
+#
+# Make hashes for the names of the character classes and
+# for the names of the actions that appeared.
+#
+for ($state=1; $state < $num_states; $state++) {
+ if ($state_char_class[$state] ne "") {
+ if ($charClasses{$state_char_class[$state]} == 0) {
+ $charClasses{$state_char_class[$state]} = 1;
+ }
+ }
+ if ($state_func_name[$state] eq "") {
+ $state_func_name[$state] = "doNOP";
+ }
+ if ($actions{$state_action_name[$state]} == 0) {
+ $actions{$state_func_name[$state]} = 1;
+ }
+}
+
+#
+# Check that all of the destination states have been defined
+#
+#
+$states{"exit"} = 0; # Predefined state name, terminates state machine.
+for ($state=1; $state<$num_states; $state++) {
+ if ($states{$state_dest_state[$state]} == 0 && $state_dest_state[$state] ne "exit") {
+ print "Error at line $state_line_num[$state]: target state \"$state_dest_state[$state]\" is not defined.\n";
+ $errors++;
+ }
+ if ($state_push_state[$state] ne "" && $states{$state_push_state[$state]} == 0) {
+ print "Error at line $state_line_num[$state]: target state \"$state_push_state[$state]\" is not defined.\n";
+ $errors++;
+ }
+}
+
+die if ($errors>0);
+
+#
+# Assign numbers to each of the character classes classes used.
+# Sets are numbered from 128 - 250
+# The values 0-127 in the state table are used for matching
+# individual ASCII characters (the only thing that can appear in the rules.)
+# The "set" names appearing in the code below (default, etc.) need special
+# handling because they do not correspond to a normal set of characters,
+# but trigger special handling by code in the state machine.
+#
+$i = 128;
+foreach $setName (sort keys %charClasses) {
+ if ($setName eq "default") {
+ $charClasses{$setName} = 255;}
+ elsif ($setName eq "escaped") {
+ $charClasses{$setName} = 254;}
+ elsif ($setName eq "escapedP") {
+ $charClasses{$setName} = 253;}
+ elsif ($setName eq "eof") {
+ $charClasses{$setName} = 252;}
+ else {
+ # Normal (single) character class. Number them.
+ $charClasses{$setName} = $i;
+ $i++;
+ }
+}
+
+
+my ($sec, $min, $hour, , $day, $mon, $year, $wday, $yday, $isdst) = localtime;
+$year += 1900;
+
+if ($javaOutput) {
+ print "/*\n";
+ print " *******************************************************************************\n";
+ print " * Copyright (C) 2003-$year,\n";
+ print " * International Business Machines Corporation and others. All Rights Reserved.\n";
+ print " *******************************************************************************\n";
+ print " */\n";
+ print " \n";
+ print "package com.ibm.icu.text;\n";
+ print " \n";
+ print "/**\n";
+ print " * Generated Java File. Do not edit by hand.\n";
+ print " * This file contains the state table for the ICU Rule Based Break Iterator\n";
+ print " * rule parser.\n";
+ print " * It is generated by the Perl script \"rbbicst.pl\" from\n";
+ print " * the rule parser state definitions file \"rbbirpt.txt\".\n";
+ print " * \@internal \n";
+ print " *\n";
+ print " */\n";
+
+ print "class RBBIRuleParseTable\n";
+ print "{\n";
+
+ #
+ # Emit the constants for the actions to be performed.
+ #
+ $n = 1;
+ foreach $act (sort keys %actions) {
+ print " static final short $act = $n;\n";
+ $n++;
+ }
+ print " \n";
+
+ #
+ # Emit constants for char class names
+ #
+ foreach $setName (sort keys %charClasses) {
+ print " static final short kRuleSet_$setName = $charClasses{$setName};\n";
+ }
+ print "\n\n";
+
+
+ print " static class RBBIRuleTableElement { \n";
+ print " short fAction; \n";
+ print " short fCharClass; \n";
+ print " short fNextState; \n";
+ print " short fPushState; \n";
+ print " boolean fNextChar; \n";
+ print " String fStateName; \n";
+ print " RBBIRuleTableElement(short a, int cc, int ns, int ps, boolean nc, String sn) { \n";
+ print " fAction = a; \n";
+ print " fCharClass = (short)cc; \n";
+ print " fNextState = (short)ns; \n";
+ print " fPushState = (short)ps; \n";
+ print " fNextChar = nc; \n";
+ print " fStateName = sn; \n";
+ print " } \n";
+ print " }; \n";
+ print " \n";
+
+
+ print " static RBBIRuleTableElement[] gRuleParseStateTable = { \n ";
+ print " new RBBIRuleTableElement(doNOP, 0, 0,0, true, null ) // 0 \n"; #output the unused state 0.
+ for ($state=1; $state < $num_states; $state++) {
+ print " , new RBBIRuleTableElement($state_func_name[$state],";
+ if ($state_literal_chars[$state] ne "") {
+ $c = $state_literal_chars[$state];
+ print("'$c', ");
+ }else {
+ print " $charClasses{$state_char_class[$state]},";
+ }
+ print " $states{$state_dest_state[$state]},";
+
+ # The push-state field is optional. If omitted, fill field with a zero, which flags
+ # the state machine that there is no push state.
+ if ($state_push_state[$state] eq "") {
+ print "0, ";
+ } else {
+ print " $states{$state_push_state[$state]},";
+ }
+ print " $state_flag[$state], ";
+
+ # if this is the first row of the table for this state, put out the state name.
+ if ($stateNames[$state] ne "") {
+ print " \"$stateNames[$state]\") ";
+ } else {
+ print " null ) ";
+ }
+
+ # Put out a comment showing the number (index) of this state row,
+ print " // $state ";
+ print "\n";
+ }
+ print " };\n";
+
+ print "}; \n";
+
+}
+else
+{
+ #
+ # C++ Output ...
+ #
+
+
+ print "//---------------------------------------------------------------------------------\n";
+ print "//\n";
+ print "// Generated Header File. Do not edit by hand.\n";
+ print "// This file contains the state table for the ICU Rule Based Break Iterator\n";
+ print "// rule parser.\n";
+ print "// It is generated by the Perl script \"rbbicst.pl\" from\n";
+ print "// the rule parser state definitions file \"rbbirpt.txt\".\n";
+ print "//\n";
+ print "// Copyright (C) 2002-$year International Business Machines Corporation \n";
+ print "// and others. All rights reserved. \n";
+ print "//\n";
+ print "//---------------------------------------------------------------------------------\n";
+ print "#ifndef RBBIRPT_H\n";
+ print "#define RBBIRPT_H\n";
+ print "\n";
+ print "U_NAMESPACE_BEGIN\n";
+
+ #
+ # Emit the constants for indicies of Unicode Sets
+ # Define one constant for each of the character classes encountered.
+ # At the same time, store the index corresponding to the set name back into hash.
+ #
+ print "//\n";
+ print "// Character classes for RBBI rule scanning.\n";
+ print "//\n";
+ foreach $setName (sort keys %charClasses) {
+ if ($charClasses{$setName} < 250) {
+ # Normal character class.
+ print " static const uint8_t kRuleSet_$setName = $charClasses{$setName};\n";
+ }
+ }
+ print "\n\n";
+
+ #
+ # Emit the enum for the actions to be performed.
+ #
+ print "enum RBBI_RuleParseAction {\n";
+ foreach $act (sort keys %actions) {
+ print " $act,\n";
+ }
+ print " rbbiLastAction};\n\n";
+
+ #
+ # Emit the struct definition for transtion table elements.
+ #
+ print "//-------------------------------------------------------------------------------\n";
+ print "//\n";
+ print "// RBBIRuleTableEl represents the structure of a row in the transition table\n";
+ print "// for the rule parser state machine.\n";
+ print "//-------------------------------------------------------------------------------\n";
+ print "struct RBBIRuleTableEl {\n";
+ print " RBBI_RuleParseAction fAction;\n";
+ print " uint8_t fCharClass; // 0-127: an individual ASCII character\n";
+ print " // 128-255: character class index\n";
+ print " uint8_t fNextState; // 0-250: normal next-stat numbers\n";
+ print " // 255: pop next-state from stack.\n";
+ print " uint8_t fPushState;\n";
+ print " UBool fNextChar;\n";
+ print "};\n\n";
+
+ #
+ # emit the state transition table
+ #
+ print "static const struct RBBIRuleTableEl gRuleParseStateTable[] = {\n";
+ print " {doNOP, 0, 0, 0, TRUE}\n"; # State 0 is a dummy. Real states start with index = 1.
+ for ($state=1; $state < $num_states; $state++) {
+ print " , {$state_func_name[$state],";
+ if ($state_literal_chars[$state] ne "") {
+ $c = $state_literal_chars[$state];
+ printf(" %d /* $c */,", ord($c)); # use numeric value, so EBCDIC machines are ok.
+ }else {
+ print " $charClasses{$state_char_class[$state]},";
+ }
+ print " $states{$state_dest_state[$state]},";
+
+ # The push-state field is optional. If omitted, fill field with a zero, which flags
+ # the state machine that there is no push state.
+ if ($state_push_state[$state] eq "") {
+ print "0, ";
+ } else {
+ print " $states{$state_push_state[$state]},";
+ }
+ print " $state_flag[$state]} ";
+
+ # Put out a C++ comment showing the number (index) of this state row,
+ # and, if this is the first row of the table for this state, the state name.
+ print " // $state ";
+ if ($stateNames[$state] ne "") {
+ print " $stateNames[$state]";
+ }
+ print "\n";
+ };
+ print " };\n";
+
+
+ #
+ # emit a mapping array from state numbers to state names.
+ #
+ # This array is used for producing debugging output from the rule parser.
+ #
+ print "#ifdef RBBI_DEBUG\n";
+ print "static const char * const RBBIRuleStateNames[] = {";
+ for ($state=0; $state<$num_states; $state++) {
+ if ($stateNames[$state] ne "") {
+ print " \"$stateNames[$state]\",\n";
+ } else {
+ print " 0,\n";
+ }
+ }
+ print " 0};\n";
+ print "#endif\n\n";
+
+ print "U_NAMESPACE_END\n";
+ print "#endif\n";
+}
+
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbidata.cpp b/Build/source/libs/icu/icu-xetex/common/rbbidata.cpp
new file mode 100644
index 00000000000..7897b44e7b9
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbidata.cpp
@@ -0,0 +1,444 @@
+/*
+***************************************************************************
+* Copyright (C) 1999-2007 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/utypes.h"
+#include "rbbidata.h"
+#include "rbbirb.h"
+#include "utrie.h"
+#include "udatamem.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "umutex.h"
+
+#include "uassert.h"
+
+
+//-----------------------------------------------------------------------------------
+//
+// Trie access folding function. Copied as-is from properties code in uchar.c
+//
+//-----------------------------------------------------------------------------------
+U_CDECL_BEGIN
+static int32_t U_CALLCONV
+getFoldingOffset(uint32_t data) {
+ /* if bit 15 is set, then the folding offset is in bits 14..0 of the 16-bit trie result */
+ if(data&0x8000) {
+ return (int32_t)(data&0x7fff);
+ } else {
+ return 0;
+ }
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+//-----------------------------------------------------------------------------
+//
+// Constructors.
+//
+//-----------------------------------------------------------------------------
+RBBIDataWrapper::RBBIDataWrapper(const RBBIDataHeader *data, UErrorCode &status) {
+ init(data, status);
+}
+
+RBBIDataWrapper::RBBIDataWrapper(UDataMemory* udm, UErrorCode &status) {
+ const RBBIDataHeader *d = (const RBBIDataHeader *)
+ // ((char *)&(udm->pHeader->info) + udm->pHeader->info.size);
+ // taking into consideration the padding added in by udata_write
+ ((char *)(udm->pHeader) + udm->pHeader->dataHeader.headerSize);
+ init(d, status);
+ fUDataMem = udm;
+}
+
+//-----------------------------------------------------------------------------
+//
+// init(). Does most of the work of construction, shared between the
+// constructors.
+//
+//-----------------------------------------------------------------------------
+void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fHeader = data;
+ if (fHeader->fMagic != 0xb1a0 ||
+ !(fHeader->fFormatVersion[0] == 3 || // ICU 3.4
+ *(int32_t *)fHeader->fFormatVersion == 1)) // ICU 3.2 and earlier.
+ {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ fUDataMem = NULL;
+ fReverseTable = NULL;
+ fSafeFwdTable = NULL;
+ fSafeRevTable = NULL;
+ if (data->fFTableLen != 0) {
+ fForwardTable = (RBBIStateTable *)((char *)data + fHeader->fFTable);
+ }
+ if (data->fRTableLen != 0) {
+ fReverseTable = (RBBIStateTable *)((char *)data + fHeader->fRTable);
+ }
+ if (data->fSFTableLen != 0) {
+ fSafeFwdTable = (RBBIStateTable *)((char *)data + fHeader->fSFTable);
+ }
+ if (data->fSRTableLen != 0) {
+ fSafeRevTable = (RBBIStateTable *)((char *)data + fHeader->fSRTable);
+ }
+
+
+ utrie_unserialize(&fTrie,
+ (uint8_t *)data + fHeader->fTrie,
+ fHeader->fTrieLen,
+ &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fTrie.getFoldingOffset=getFoldingOffset;
+
+
+ fRuleSource = (UChar *)((char *)data + fHeader->fRuleSource);
+ fRuleString.setTo(TRUE, fRuleSource, -1);
+ U_ASSERT(data->fRuleSourceLen > 0);
+
+ fRuleStatusTable = (int32_t *)((char *)data + fHeader->fStatusTable);
+ fStatusMaxIdx = data->fStatusTableLen / sizeof(int32_t);
+
+ fRefCount = 1;
+
+#ifdef RBBI_DEBUG
+ char *debugEnv = getenv("U_RBBIDEBUG");
+ if (debugEnv && uprv_strstr(debugEnv, "data")) {this->printData();}
+#endif
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// Destructor. Don't call this - use removeReference() instead.
+//
+//-----------------------------------------------------------------------------
+RBBIDataWrapper::~RBBIDataWrapper() {
+ U_ASSERT(fRefCount == 0);
+ if (fUDataMem) {
+ udata_close(fUDataMem);
+ } else {
+ uprv_free((void *)fHeader);
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// Operator == Consider two RBBIDataWrappers to be equal if they
+// refer to the same underlying data. Although
+// the data wrappers are normally shared between
+// iterator instances, it's possible to independently
+// open the same data twice, and get two instances, which
+// should still be ==.
+//
+//-----------------------------------------------------------------------------
+UBool RBBIDataWrapper::operator ==(const RBBIDataWrapper &other) const {
+ if (fHeader == other.fHeader) {
+ return TRUE;
+ }
+ if (fHeader->fLength != other.fHeader->fLength) {
+ return FALSE;
+ }
+ if (uprv_memcmp(fHeader, other.fHeader, fHeader->fLength) == 0) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int32_t RBBIDataWrapper::hashCode() {
+ return fHeader->fFTableLen;
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// Reference Counting. A single RBBIDataWrapper object is shared among
+// however many RulesBasedBreakIterator instances are
+// referencing the same data.
+//
+//-----------------------------------------------------------------------------
+void RBBIDataWrapper::removeReference() {
+ if (umtx_atomic_dec(&fRefCount) == 0) {
+ delete this;
+ }
+}
+
+
+RBBIDataWrapper *RBBIDataWrapper::addReference() {
+ umtx_atomic_inc(&fRefCount);
+ return this;
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// getRuleSourceString
+//
+//-----------------------------------------------------------------------------
+const UnicodeString &RBBIDataWrapper::getRuleSourceString() const {
+ return fRuleString;
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// print - debugging function to dump the runtime data tables.
+//
+//-----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBIDataWrapper::printTable(const char *heading, const RBBIStateTable *table) {
+ uint32_t c;
+ uint32_t s;
+
+ RBBIDebugPrintf(" %s\n", heading);
+
+ RBBIDebugPrintf("State | Acc LA TagIx");
+ for (c=0; cfCatCount; c++) {RBBIDebugPrintf("%3d ", c);}
+ RBBIDebugPrintf("\n------|---------------"); for (c=0;cfCatCount; c++) {
+ RBBIDebugPrintf("----");
+ }
+ RBBIDebugPrintf("\n");
+
+ if (table == NULL) {
+ RBBIDebugPrintf(" N U L L T A B L E\n\n");
+ return;
+ }
+ for (s=0; sfNumStates; s++) {
+ RBBIStateTableRow *row = (RBBIStateTableRow *)
+ (table->fTableData + (table->fRowLen * s));
+ RBBIDebugPrintf("%4d | %3d %3d %3d ", s, row->fAccepting, row->fLookAhead, row->fTagIdx);
+ for (c=0; cfCatCount; c++) {
+ RBBIDebugPrintf("%3d ", row->fNextState[c]);
+ }
+ RBBIDebugPrintf("\n");
+ }
+ RBBIDebugPrintf("\n");
+}
+#endif
+
+
+#ifdef RBBI_DEBUG
+void RBBIDataWrapper::printData() {
+ RBBIDebugPrintf("RBBI Data at %p\n", (void *)fHeader);
+ RBBIDebugPrintf(" Version = {%d %d %d %d}\n", fHeader->fFormatVersion[0], fHeader->fFormatVersion[1],
+ fHeader->fFormatVersion[2], fHeader->fFormatVersion[3]);
+ RBBIDebugPrintf(" total length of data = %d\n", fHeader->fLength);
+ RBBIDebugPrintf(" number of character categories = %d\n\n", fHeader->fCatCount);
+
+ printTable("Forward State Transition Table", fForwardTable);
+ printTable("Reverse State Transition Table", fReverseTable);
+ printTable("Safe Forward State Transition Table", fSafeFwdTable);
+ printTable("Safe Reverse State Transition Table", fSafeRevTable);
+
+ RBBIDebugPrintf("\nOrignal Rules source:\n");
+ for (int32_t c=0; fRuleSource[c] != 0; c++) {
+ RBBIDebugPrintf("%c", fRuleSource[c]);
+ }
+ RBBIDebugPrintf("\n\n");
+}
+#endif
+
+
+U_NAMESPACE_END
+U_NAMESPACE_USE
+
+//-----------------------------------------------------------------------------
+//
+// ubrk_swap - byte swap and char encoding swap of RBBI data
+//
+//-----------------------------------------------------------------------------
+
+U_CAPI int32_t U_EXPORT2
+ubrk_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData,
+ UErrorCode *status) {
+
+ if (status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+ if(ds==NULL || inData==NULL || length<-1 || (length>0 && outData==NULL)) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ //
+ // Check that the data header is for for break data.
+ // (Header contents are defined in genbrk.cpp)
+ //
+ const UDataInfo *pInfo = (const UDataInfo *)((const char *)inData+4);
+ if(!( pInfo->dataFormat[0]==0x42 && /* dataFormat="Brk " */
+ pInfo->dataFormat[1]==0x72 &&
+ pInfo->dataFormat[2]==0x6b &&
+ pInfo->dataFormat[3]==0x20 &&
+ pInfo->formatVersion[0]==3 )) {
+ udata_printError(ds, "ubrk_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0]);
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Swap the data header. (This is the generic ICU Data Header, not the RBBI Specific
+ // RBBIDataHeader). This swap also conveniently gets us
+ // the size of the ICU d.h., which lets us locate the start
+ // of the RBBI specific data.
+ //
+ int32_t headerSize=udata_swapDataHeader(ds, inData, length, outData, status);
+
+
+ //
+ // Get the RRBI Data Header, and check that it appears to be OK.
+ //
+ // Note: ICU 3.2 and earlier, RBBIDataHeader::fDataFormat was actually
+ // an int32_t with a value of 1. Starting with ICU 3.4,
+ // RBBI's fDataFormat matches the dataFormat field from the
+ // UDataInfo header, four int8_t bytes. The value is {3,1,0,0}
+ //
+ const uint8_t *inBytes =(const uint8_t *)inData+headerSize;
+ RBBIDataHeader *rbbiDH = (RBBIDataHeader *)inBytes;
+ UBool formatVersionOne = ds->readUInt32(*(int32_t *)rbbiDH->fFormatVersion) == 1;
+ if (ds->readUInt32(rbbiDH->fMagic) != 0xb1a0 ||
+ !(formatVersionOne || rbbiDH->fFormatVersion[0] == 3) ||
+ ds->readUInt32(rbbiDH->fLength) < sizeof(RBBIDataHeader))
+ {
+ udata_printError(ds, "ubrk_swap(): RBBI Data header is invalid.\n");
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Prefight operation? Just return the size
+ //
+ int32_t breakDataLength = ds->readUInt32(rbbiDH->fLength);
+ int32_t totalSize = headerSize + breakDataLength;
+ if (length < 0) {
+ return totalSize;
+ }
+
+ //
+ // Check that length passed in is consistent with length from RBBI data header.
+ //
+ if (length < totalSize) {
+ udata_printError(ds, "ubrk_swap(): too few bytes (%d after ICU Data header) for break data.\n",
+ breakDataLength);
+ *status=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+
+ //
+ // Swap the Data. Do the data itself first, then the RBBI Data Header, because
+ // we need to reference the header to locate the data, and an
+ // inplace swap of the header leaves it unusable.
+ //
+ uint8_t *outBytes = (uint8_t *)outData + headerSize;
+ RBBIDataHeader *outputDH = (RBBIDataHeader *)outBytes;
+
+ int32_t tableStartOffset;
+ int32_t tableLength;
+
+ //
+ // If not swapping in place, zero out the output buffer before starting.
+ // Individual tables and other data items within are aligned to 8 byte boundaries
+ // when originally created. Any unused space between items needs to be zero.
+ //
+ if (inBytes != outBytes) {
+ uprv_memset(outBytes, 0, breakDataLength);
+ }
+
+ //
+ // Each state table begins with several 32 bit fields. Calculate the size
+ // in bytes of these.
+ //
+ int32_t topSize = offsetof(RBBIStateTable, fTableData);
+
+ // Forward state table.
+ tableStartOffset = ds->readUInt32(rbbiDH->fFTable);
+ tableLength = ds->readUInt32(rbbiDH->fFTableLen);
+
+ if (tableLength > 0) {
+ ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
+ outBytes+tableStartOffset, status);
+ ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
+ outBytes+tableStartOffset+topSize, status);
+ }
+
+ // Reverse state table. Same layout as forward table, above.
+ tableStartOffset = ds->readUInt32(rbbiDH->fRTable);
+ tableLength = ds->readUInt32(rbbiDH->fRTableLen);
+
+ if (tableLength > 0) {
+ ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
+ outBytes+tableStartOffset, status);
+ ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
+ outBytes+tableStartOffset+topSize, status);
+ }
+
+ // Safe Forward state table. Same layout as forward table, above.
+ tableStartOffset = ds->readUInt32(rbbiDH->fSFTable);
+ tableLength = ds->readUInt32(rbbiDH->fSFTableLen);
+
+ if (tableLength > 0) {
+ ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
+ outBytes+tableStartOffset, status);
+ ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
+ outBytes+tableStartOffset+topSize, status);
+ }
+
+ // Safe Reverse state table. Same layout as forward table, above.
+ tableStartOffset = ds->readUInt32(rbbiDH->fSRTable);
+ tableLength = ds->readUInt32(rbbiDH->fSRTableLen);
+
+ if (tableLength > 0) {
+ ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
+ outBytes+tableStartOffset, status);
+ ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
+ outBytes+tableStartOffset+topSize, status);
+ }
+
+ // Trie table for character categories
+ utrie_swap(ds, inBytes+ds->readUInt32(rbbiDH->fTrie), ds->readUInt32(rbbiDH->fTrieLen),
+ outBytes+ds->readUInt32(rbbiDH->fTrie), status);
+
+ // Source Rules Text. It's UChar data
+ ds->swapArray16(ds, inBytes+ds->readUInt32(rbbiDH->fRuleSource), ds->readUInt32(rbbiDH->fRuleSourceLen),
+ outBytes+ds->readUInt32(rbbiDH->fRuleSource), status);
+
+ // Table of rule status values. It's all int_32 values
+ ds->swapArray32(ds, inBytes+ds->readUInt32(rbbiDH->fStatusTable), ds->readUInt32(rbbiDH->fStatusTableLen),
+ outBytes+ds->readUInt32(rbbiDH->fStatusTable), status);
+
+ // And, last, the header.
+ // For the old version one format, the entire header consists of int32_t values.
+ // For the newer formats, the fDataFormat field is an array of four bytes.
+ // Swap the whole thing as int32_t, then, for the newer format, re-swap the one field.
+ //
+ ds->swapArray32(ds, inBytes, sizeof(RBBIDataHeader), outBytes, status);
+ if (formatVersionOne == FALSE) {
+ ds->swapArray32(ds, outputDH->fFormatVersion, 4, outputDH->fFormatVersion, status);
+ }
+
+
+ return totalSize;
+}
+
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbidata.h b/Build/source/libs/icu/icu-xetex/common/rbbidata.h
new file mode 100644
index 00000000000..7ba1db05d65
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbidata.h
@@ -0,0 +1,193 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 1999-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: rbbidata.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* RBBI data formats Includes
+*
+* Structs that describes the format of the Binary RBBI data,
+* as it is stored in ICU's data file.
+*
+* RBBIDataWrapper - Instances of this class sit between the
+* raw data structs and the RulesBasedBreakIterator objects
+* that are created by applications. The wrapper class
+* provides reference counting for the underlying data,
+* and direct pointers to data that would not otherwise
+* be accessible without ugly pointer arithmetic. The
+* wrapper does not attempt to provide any higher level
+* abstractions for the data itself.
+*
+* There will be only one instance of RBBIDataWrapper for any
+* set of RBBI run time data being shared by instances
+* (clones) of RulesBasedBreakIterator.
+*/
+
+#ifndef __RBBIDATA_H__
+#define __RBBIDATA_H__
+
+#include "unicode/utypes.h"
+#include "unicode/udata.h"
+#include "udataswp.h"
+
+/**
+ * Swap RBBI data. See udataswp.h.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+ubrk_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+#ifdef XP_CPLUSPLUS
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "utrie.h"
+
+U_NAMESPACE_BEGIN
+
+/*
+ * The following structs map exactly onto the raw data from ICU common data file.
+ */
+struct RBBIDataHeader {
+ uint32_t fMagic; /* == 0xbla0 */
+ uint8_t fFormatVersion[4]; /* Data Format. Same as the value in struct UDataInfo */
+ /* if there is one associated with this data. */
+ /* (version originates in rbbi, is copied to UDataInfo) */
+ /* For ICU 3.2 and earlier, this field was */
+ /* uint32_t fVersion */
+ /* with a value of 1. */
+ uint32_t fLength; /* Total length in bytes of this RBBI Data, */
+ /* including all sections, not just the header. */
+ uint32_t fCatCount; /* Number of character categories. */
+
+ /* */
+ /* Offsets and sizes of each of the subsections within the RBBI data. */
+ /* All offsets are bytes from the start of the RBBIDataHeader. */
+ /* All sizes are in bytes. */
+ /* */
+ uint32_t fFTable; /* forward state transition table. */
+ uint32_t fFTableLen;
+ uint32_t fRTable; /* Offset to the reverse state transition table. */
+ uint32_t fRTableLen;
+ uint32_t fSFTable; /* safe point forward transition table */
+ uint32_t fSFTableLen;
+ uint32_t fSRTable; /* safe point reverse transition table */
+ uint32_t fSRTableLen;
+ uint32_t fTrie; /* Offset to Trie data for character categories */
+ uint32_t fTrieLen;
+ uint32_t fRuleSource; /* Offset to the source for for the break */
+ uint32_t fRuleSourceLen; /* rules. Stored UChar *. */
+ uint32_t fStatusTable; /* Offset to the table of rule status values */
+ uint32_t fStatusTableLen;
+
+ uint32_t fReserved[6]; /* Reserved for expansion */
+
+};
+
+
+
+struct RBBIStateTableRow {
+ int16_t fAccepting; /* Non-zero if this row is for an accepting state. */
+ /* Value 0: not an accepting state. */
+ /* -1: Unconditional Accepting state. */
+ /* positive: Look-ahead match has completed. */
+ /* Actual boundary position happened earlier */
+ /* Value here == fLookAhead in earlier */
+ /* state, at actual boundary pos. */
+ int16_t fLookAhead; /* Non-zero if this row is for a state that */
+ /* corresponds to a '/' in the rule source. */
+ /* Value is the same as the fAccepting */
+ /* value for the rule (which will appear */
+ /* in a different state. */
+ int16_t fTagIdx; /* Non-zero if this row covers a {tagged} position */
+ /* from a rule. Value is the index in the */
+ /* StatusTable of the set of matching */
+ /* tags (rule status values) */
+ int16_t fReserved;
+ uint16_t fNextState[2]; /* Next State, indexed by char category. */
+ /* Array Size is fNumCols from the */
+ /* state table header. */
+ /* CAUTION: see RBBITableBuilder::getTableSize() */
+ /* before changing anything here. */
+};
+
+
+struct RBBIStateTable {
+ uint32_t fNumStates; /* Number of states. */
+ uint32_t fRowLen; /* Length of a state table row, in bytes. */
+ uint32_t fFlags; /* Option Flags for this state table */
+ uint32_t fReserved; /* reserved */
+ char fTableData[4]; /* First RBBIStateTableRow begins here. */
+ /* (making it char[] simplifies ugly address */
+ /* arithmetic for indexing variable length rows.) */
+};
+
+typedef enum {
+ RBBI_LOOKAHEAD_HARD_BREAK = 1,
+ RBBI_BOF_REQUIRED = 2
+} RBBIStateTableFlags;
+
+
+/* */
+/* The reference counting wrapper class */
+/* */
+class RBBIDataWrapper : public UMemory {
+public:
+ RBBIDataWrapper(const RBBIDataHeader *data, UErrorCode &status);
+ RBBIDataWrapper(UDataMemory* udm, UErrorCode &status);
+ ~RBBIDataWrapper();
+
+ void init(const RBBIDataHeader *data, UErrorCode &status);
+ RBBIDataWrapper *addReference();
+ void removeReference();
+ UBool operator ==(const RBBIDataWrapper &other) const;
+ int32_t hashCode();
+ const UnicodeString &getRuleSourceString() const;
+#ifdef RBBI_DEBUG
+ void printData();
+ void printTable(const char *heading, const RBBIStateTable *table);
+#else
+ #define printData()
+ #define printTable(heading, table)
+#endif
+
+ /* */
+ /* Pointers to items within the data */
+ /* */
+ const RBBIDataHeader *fHeader;
+ const RBBIStateTable *fForwardTable;
+ const RBBIStateTable *fReverseTable;
+ const RBBIStateTable *fSafeFwdTable;
+ const RBBIStateTable *fSafeRevTable;
+ const UChar *fRuleSource;
+ const int32_t *fRuleStatusTable;
+
+ /* number of int32_t values in the rule status table. Used to sanity check indexing */
+ int32_t fStatusMaxIdx;
+
+ UTrie fTrie;
+
+private:
+ int32_t fRefCount;
+ UDataMemory *fUDataMem;
+ UnicodeString fRuleString;
+
+ RBBIDataWrapper(const RBBIDataWrapper &other); /* forbid copying of this class */
+ RBBIDataWrapper &operator=(const RBBIDataWrapper &other); /* forbid copying of this class */
+};
+
+
+
+U_NAMESPACE_END
+
+#endif /* C++ */
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbinode.cpp b/Build/source/libs/icu/icu-xetex/common/rbbinode.cpp
new file mode 100644
index 00000000000..af467b6d064
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbinode.cpp
@@ -0,0 +1,355 @@
+/*
+***************************************************************************
+* Copyright (C) 2002-2006 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+
+//
+// File: rbbinode.cpp
+//
+// Implementation of class RBBINode, which represents a node in the
+// tree generated when parsing the Rules Based Break Iterator rules.
+//
+// This "Class" is actually closer to a struct.
+// Code using it is expected to directly access fields much of the time.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/parsepos.h"
+#include "uvector.h"
+
+#include "rbbirb.h"
+#include "rbbinode.h"
+
+#include "uassert.h"
+
+
+U_NAMESPACE_BEGIN
+
+#ifdef RBBI_DEBUG
+static int gLastSerial = 0;
+#endif
+
+
+//-------------------------------------------------------------------------
+//
+// Constructor. Just set the fields to reasonable default values.
+//
+//-------------------------------------------------------------------------
+RBBINode::RBBINode(NodeType t) : UMemory() {
+#ifdef RBBI_DEBUG
+ fSerialNum = ++gLastSerial;
+#endif
+ fType = t;
+ fParent = NULL;
+ fLeftChild = NULL;
+ fRightChild = NULL;
+ fInputSet = NULL;
+ fFirstPos = 0;
+ fLastPos = 0;
+ fNullable = FALSE;
+ fLookAheadEnd = FALSE;
+ fVal = 0;
+ fPrecedence = precZero;
+
+ UErrorCode status = U_ZERO_ERROR;
+ fFirstPosSet = new UVector(status); // TODO - get a real status from somewhere
+ fLastPosSet = new UVector(status);
+ fFollowPos = new UVector(status);
+ if (t==opCat) {fPrecedence = precOpCat;}
+ else if (t==opOr) {fPrecedence = precOpOr;}
+ else if (t==opStart) {fPrecedence = precStart;}
+ else if (t==opLParen) {fPrecedence = precLParen;}
+
+}
+
+
+RBBINode::RBBINode(const RBBINode &other) : UMemory(other) {
+#ifdef RBBI_DEBUG
+ fSerialNum = ++gLastSerial;
+#endif
+ fType = other.fType;
+ fParent = NULL;
+ fLeftChild = NULL;
+ fRightChild = NULL;
+ fInputSet = other.fInputSet;
+ fPrecedence = other.fPrecedence;
+ fText = other.fText;
+ fFirstPos = other.fFirstPos;
+ fLastPos = other.fLastPos;
+ fNullable = other.fNullable;
+ fVal = other.fVal;
+ UErrorCode status = U_ZERO_ERROR;
+ fFirstPosSet = new UVector(status); // TODO - get a real status from somewhere
+ fLastPosSet = new UVector(status);
+ fFollowPos = new UVector(status);
+}
+
+
+//-------------------------------------------------------------------------
+//
+// Destructor. Deletes both this node AND any child nodes,
+// except in the case of variable reference nodes. For
+// these, the l. child points back to the definition, which
+// is common for all references to the variable, meaning
+// it can't be deleted here.
+//
+//-------------------------------------------------------------------------
+RBBINode::~RBBINode() {
+ // printf("deleting node %8x serial %4d\n", this, this->fSerialNum);
+ delete fInputSet;
+ fInputSet = NULL;
+
+ switch (this->fType) {
+ case varRef:
+ case setRef:
+ // for these node types, multiple instances point to the same "children"
+ // Storage ownership of children handled elsewhere. Don't delete here.
+ break;
+
+ default:
+ delete fLeftChild;
+ fLeftChild = NULL;
+ delete fRightChild;
+ fRightChild = NULL;
+ }
+
+
+ delete fFirstPosSet;
+ delete fLastPosSet;
+ delete fFollowPos;
+
+}
+
+
+//-------------------------------------------------------------------------
+//
+// cloneTree Make a copy of the subtree rooted at this node.
+// Discard any variable references encountered along the way,
+// and replace with copies of the variable's definitions.
+// Used to replicate the expression underneath variable
+// references in preparation for generating the DFA tables.
+//
+//-------------------------------------------------------------------------
+RBBINode *RBBINode::cloneTree() {
+ RBBINode *n;
+
+ if (fType == RBBINode::varRef) {
+ // If the current node is a variable reference, skip over it
+ // and clone the definition of the variable instead.
+ n = fLeftChild->cloneTree();
+ } else if (fType == RBBINode::uset) {
+ n = this;
+ } else {
+ n = new RBBINode(*this);
+ if (fLeftChild != NULL) {
+ n->fLeftChild = fLeftChild->cloneTree();
+ n->fLeftChild->fParent = n;
+ }
+ if (fRightChild != NULL) {
+ n->fRightChild = fRightChild->cloneTree();
+ n->fRightChild->fParent = n;
+ }
+ }
+ return n;
+}
+
+
+
+//-------------------------------------------------------------------------
+//
+// flattenVariables Walk a parse tree, replacing any variable
+// references with a copy of the variable's definition.
+// Aside from variables, the tree is not changed.
+//
+// Return the root of the tree. If the root was not a variable
+// reference, it remains unchanged - the root we started with
+// is the root we return. If, however, the root was a variable
+// reference, the root of the newly cloned replacement tree will
+// be returned, and the original tree deleted.
+//
+// This function works by recursively walking the tree
+// without doing anything until a variable reference is
+// found, then calling cloneTree() at that point. Any
+// nested references are handled by cloneTree(), not here.
+//
+//-------------------------------------------------------------------------
+RBBINode *RBBINode::flattenVariables() {
+ if (fType == varRef) {
+ RBBINode *retNode = fLeftChild->cloneTree();
+ delete this;
+ return retNode;
+ }
+
+ if (fLeftChild != NULL) {
+ fLeftChild = fLeftChild->flattenVariables();
+ fLeftChild->fParent = this;
+ }
+ if (fRightChild != NULL) {
+ fRightChild = fRightChild->flattenVariables();
+ fRightChild->fParent = this;
+ }
+ return this;
+}
+
+
+//-------------------------------------------------------------------------
+//
+// flattenSets Walk the parse tree, replacing any nodes of type setRef
+// with a copy of the expression tree for the set. A set's
+// equivalent expression tree is precomputed and saved as
+// the left child of the uset node.
+//
+//-------------------------------------------------------------------------
+void RBBINode::flattenSets() {
+ U_ASSERT(fType != setRef);
+
+ if (fLeftChild != NULL) {
+ if (fLeftChild->fType==setRef) {
+ RBBINode *setRefNode = fLeftChild;
+ RBBINode *usetNode = setRefNode->fLeftChild;
+ RBBINode *replTree = usetNode->fLeftChild;
+ fLeftChild = replTree->cloneTree();
+ fLeftChild->fParent = this;
+ delete setRefNode;
+ } else {
+ fLeftChild->flattenSets();
+ }
+ }
+
+ if (fRightChild != NULL) {
+ if (fRightChild->fType==setRef) {
+ RBBINode *setRefNode = fRightChild;
+ RBBINode *usetNode = setRefNode->fLeftChild;
+ RBBINode *replTree = usetNode->fLeftChild;
+ fRightChild = replTree->cloneTree();
+ fRightChild->fParent = this;
+ delete setRefNode;
+ } else {
+ fRightChild->flattenSets();
+ }
+ }
+}
+
+
+
+//-------------------------------------------------------------------------
+//
+// findNodes() Locate all the nodes of the specified type, starting
+// at the specified root.
+//
+//-------------------------------------------------------------------------
+void RBBINode::findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status) {
+ /* test for buffer overflows */
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fType == kind) {
+ dest->addElement(this, status);
+ }
+ if (fLeftChild != NULL) {
+ fLeftChild->findNodes(dest, kind, status);
+ }
+ if (fRightChild != NULL) {
+ fRightChild->findNodes(dest, kind, status);
+ }
+}
+
+
+//-------------------------------------------------------------------------
+//
+// print. Print out a single node, for debugging.
+//
+//-------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBINode::printNode() {
+ static const char * const nodeTypeNames[] = {
+ "setRef",
+ "uset",
+ "varRef",
+ "leafChar",
+ "lookAhead",
+ "tag",
+ "endMark",
+ "opStart",
+ "opCat",
+ "opOr",
+ "opStar",
+ "opPlus",
+ "opQuestion",
+ "opBreak",
+ "opReverse",
+ "opLParen"
+ };
+
+ if (this==NULL) {
+ RBBIDebugPrintf("%10p", (void *)this);
+ } else {
+ RBBIDebugPrintf("%10p %12s %10p %10p %10p %4d %6d %d ",
+ (void *)this, nodeTypeNames[fType], (void *)fParent, (void *)fLeftChild, (void *)fRightChild,
+ fSerialNum, fFirstPos, fVal);
+ if (fType == varRef) {
+ RBBI_DEBUG_printUnicodeString(fText);
+ }
+ }
+ RBBIDebugPrintf("\n");
+}
+#endif
+
+
+#ifdef RBBI_DEBUG
+U_CFUNC void RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth)
+{
+ int i;
+ for (i=0; iprintNode();
+ if (this != NULL) {
+ // Only dump the definition under a variable reference if asked to.
+ // Unconditinally dump children of all other node types.
+ if (fType != varRef) {
+ if (fLeftChild != NULL) {
+ fLeftChild->printTree(FALSE);
+ }
+
+ if (fRightChild != NULL) {
+ fRightChild->printTree(FALSE);
+ }
+ }
+ }
+}
+#endif
+
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbinode.h b/Build/source/libs/icu/icu-xetex/common/rbbinode.h
new file mode 100644
index 00000000000..0cbf6a71abe
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbinode.h
@@ -0,0 +1,118 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 2001-2006, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+
+#ifndef RBBINODE_H
+#define RBBINODE_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+
+//
+// class RBBINode
+//
+// Represents a node in the parse tree generated when reading
+// a rule file.
+//
+
+U_NAMESPACE_BEGIN
+
+class UnicodeSet;
+class UVector;
+
+class RBBINode : public UMemory {
+ public:
+ enum NodeType {
+ setRef,
+ uset,
+ varRef,
+ leafChar,
+ lookAhead,
+ tag,
+ endMark,
+ opStart,
+ opCat,
+ opOr,
+ opStar,
+ opPlus,
+ opQuestion,
+ opBreak,
+ opReverse,
+ opLParen
+ };
+
+ enum OpPrecedence {
+ precZero,
+ precStart,
+ precLParen,
+ precOpOr,
+ precOpCat
+ };
+
+ NodeType fType;
+ RBBINode *fParent;
+ RBBINode *fLeftChild;
+ RBBINode *fRightChild;
+ UnicodeSet *fInputSet; // For uset nodes only.
+ OpPrecedence fPrecedence; // For binary ops only.
+
+ UnicodeString fText; // Text corresponding to this node.
+ // May be lazily evaluated when (if) needed
+ // for some node types.
+ int fFirstPos; // Position in the rule source string of the
+ // first text associated with the node.
+ // If there's a left child, this will be the same
+ // as that child's left pos.
+ int fLastPos; // Last position in the rule source string
+ // of any text associated with this node.
+ // If there's a right child, this will be the same
+ // as that child's last postion.
+
+ UBool fNullable; // See Aho.
+ int32_t fVal; // For leafChar nodes, the value.
+ // Values are the character category,
+ // corresponds to columns in the final
+ // state transition table.
+
+ UBool fLookAheadEnd; // For endMark nodes, set TRUE if
+ // marking the end of a look-ahead rule.
+
+ UVector *fFirstPosSet;
+ UVector *fLastPosSet; // TODO: rename fFirstPos & fLastPos to avoid confusion.
+ UVector *fFollowPos;
+
+
+ RBBINode(NodeType t);
+ RBBINode(const RBBINode &other);
+ ~RBBINode();
+
+ RBBINode *cloneTree();
+ RBBINode *flattenVariables();
+ void flattenSets();
+ void findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status);
+
+#ifdef RBBI_DEBUG
+ void printNode();
+ void printTree(UBool withHeading);
+#endif
+
+ private:
+ RBBINode &operator = (const RBBINode &other); // No defs.
+ UBool operator == (const RBBINode &other); // Private, so these functions won't accidently be used.
+
+#ifdef RBBI_DEBUG
+ int fSerialNum; // Debugging aids.
+#endif
+};
+
+#ifdef RBBI_DEBUG
+U_CFUNC void
+RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0);
+#endif
+
+U_NAMESPACE_END
+
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbirb.cpp b/Build/source/libs/icu/icu-xetex/common/rbbirb.cpp
new file mode 100644
index 00000000000..a3d32c396ff
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbirb.cpp
@@ -0,0 +1,312 @@
+//
+// file: rbbirb.cpp
+//
+// Copyright (C) 2002-2005, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains the RBBIRuleBuilder class implementation. This is the main class for
+// building (compiling) break rules into the tables required by the runtime
+// RBBI engine.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/brkiter.h"
+#include "unicode/rbbi.h"
+#include "unicode/ubrk.h"
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/uchriter.h"
+#include "unicode/parsepos.h"
+#include "unicode/parseerr.h"
+#include "cmemory.h"
+#include "cstring.h"
+
+#include "rbbirb.h"
+#include "rbbinode.h"
+
+#include "rbbiscan.h"
+#include "rbbisetb.h"
+#include "rbbitblb.h"
+#include "rbbidata.h"
+
+
+U_NAMESPACE_BEGIN
+
+
+//----------------------------------------------------------------------------------------
+//
+// Constructor.
+//
+//----------------------------------------------------------------------------------------
+RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
+ UParseError &parseErr,
+ UErrorCode &status)
+ : fRules(rules)
+{
+ fStatus = &status; // status is checked below
+ fParseError = &parseErr;
+ fDebugEnv = NULL;
+#ifdef RBBI_DEBUG
+ fDebugEnv = getenv("U_RBBIDEBUG");
+#endif
+
+
+ fForwardTree = NULL;
+ fReverseTree = NULL;
+ fSafeFwdTree = NULL;
+ fSafeRevTree = NULL;
+ fDefaultTree = &fForwardTree;
+ fForwardTables = NULL;
+ fReverseTables = NULL;
+ fSafeFwdTables = NULL;
+ fSafeRevTables = NULL;
+ fRuleStatusVals = NULL;
+ fChainRules = FALSE;
+ fLBCMNoChain = FALSE;
+ fLookAheadHardBreak = FALSE;
+ fUSetNodes = NULL;
+ fRuleStatusVals = NULL;
+ fScanner = NULL;
+ fSetBuilder = NULL;
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ fUSetNodes = new UVector(status); // bcos status gets overwritten here
+ fRuleStatusVals = new UVector(status);
+ fScanner = new RBBIRuleScanner(this);
+ fSetBuilder = new RBBISetBuilder(this);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if(fSetBuilder == 0 || fScanner == 0 || fUSetNodes == 0 || fRuleStatusVals == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// Destructor
+//
+//----------------------------------------------------------------------------------------
+RBBIRuleBuilder::~RBBIRuleBuilder() {
+
+ int i;
+ for (i=0; ; i++) {
+ RBBINode *n = (RBBINode *)fUSetNodes->elementAt(i);
+ if (n==NULL) {
+ break;
+ }
+ delete n;
+ }
+
+ delete fUSetNodes;
+ delete fSetBuilder;
+ delete fForwardTables;
+ delete fReverseTables;
+ delete fSafeFwdTables;
+ delete fSafeRevTables;
+
+ delete fForwardTree;
+ delete fReverseTree;
+ delete fSafeFwdTree;
+ delete fSafeRevTree;
+ delete fScanner;
+ delete fRuleStatusVals;
+}
+
+
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// flattenData() - Collect up the compiled RBBI rule data and put it into
+// the format for saving in ICU data files,
+// which is also the format needed by the RBBI runtime engine.
+//
+//----------------------------------------------------------------------------------------
+static int32_t align8(int32_t i) {return (i+7) & 0xfffffff8;}
+
+RBBIDataHeader *RBBIRuleBuilder::flattenData() {
+ int32_t i;
+
+ if (U_FAILURE(*fStatus)) {
+ return NULL;
+ }
+
+ // Remove comments and whitespace from the rules to make it smaller.
+ UnicodeString strippedRules((const UnicodeString&)RBBIRuleScanner::stripRules(fRules));
+
+ // Calculate the size of each section in the data.
+ // Sizes here are padded up to a multiple of 8 for better memory alignment.
+ // Sections sizes actually stored in the header are for the actual data
+ // without the padding.
+ //
+ int32_t headerSize = align8(sizeof(RBBIDataHeader));
+ int32_t forwardTableSize = align8(fForwardTables->getTableSize());
+ int32_t reverseTableSize = align8(fReverseTables->getTableSize());
+ int32_t safeFwdTableSize = align8(fSafeFwdTables->getTableSize());
+ int32_t safeRevTableSize = align8(fSafeRevTables->getTableSize());
+ int32_t trieSize = align8(fSetBuilder->getTrieSize());
+ int32_t statusTableSize = align8(fRuleStatusVals->size() * sizeof(int32_t));
+ int32_t rulesSize = align8((strippedRules.length()+1) * sizeof(UChar));
+
+ int32_t totalSize = headerSize + forwardTableSize + reverseTableSize
+ + safeFwdTableSize + safeRevTableSize
+ + statusTableSize + trieSize + rulesSize;
+
+ RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize);
+ if (data == NULL) {
+ *fStatus = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memset(data, 0, totalSize);
+
+
+ data->fMagic = 0xb1a0;
+ data->fFormatVersion[0] = 3;
+ data->fFormatVersion[1] = 1;
+ data->fFormatVersion[2] = 0;
+ data->fFormatVersion[3] = 0;
+ data->fLength = totalSize;
+ data->fCatCount = fSetBuilder->getNumCharCategories();
+
+ data->fFTable = headerSize;
+ data->fFTableLen = forwardTableSize;
+ data->fRTable = data->fFTable + forwardTableSize;
+ data->fRTableLen = reverseTableSize;
+ data->fSFTable = data->fRTable + reverseTableSize;
+ data->fSFTableLen = safeFwdTableSize;
+ data->fSRTable = data->fSFTable + safeFwdTableSize;
+ data->fSRTableLen = safeRevTableSize;
+
+ data->fTrie = data->fSRTable + safeRevTableSize;
+ data->fTrieLen = fSetBuilder->getTrieSize();
+ data->fStatusTable = data->fTrie + trieSize;
+ data->fStatusTableLen= statusTableSize;
+ data->fRuleSource = data->fStatusTable + statusTableSize;
+ data->fRuleSourceLen = strippedRules.length() * sizeof(UChar);
+
+ uprv_memset(data->fReserved, 0, sizeof(data->fReserved));
+
+ fForwardTables->exportTable((uint8_t *)data + data->fFTable);
+ fReverseTables->exportTable((uint8_t *)data + data->fRTable);
+ fSafeFwdTables->exportTable((uint8_t *)data + data->fSFTable);
+ fSafeRevTables->exportTable((uint8_t *)data + data->fSRTable);
+ fSetBuilder->serializeTrie ((uint8_t *)data + data->fTrie);
+
+ int32_t *ruleStatusTable = (int32_t *)((uint8_t *)data + data->fStatusTable);
+ for (i=0; isize(); i++) {
+ ruleStatusTable[i] = fRuleStatusVals->elementAti(i);
+ }
+
+ strippedRules.extract((UChar *)((uint8_t *)data+data->fRuleSource), rulesSize/2+1, *fStatus);
+
+ return data;
+}
+
+
+
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// createRuleBasedBreakIterator construct from source rules that are passed in
+// in a UnicodeString
+//
+//----------------------------------------------------------------------------------------
+BreakIterator *
+RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
+ UParseError &parseError,
+ UErrorCode &status)
+{
+ // status checked below
+
+ //
+ // Read the input rules, generate a parse tree, symbol table,
+ // and list of all Unicode Sets referenced by the rules.
+ //
+ RBBIRuleBuilder builder(rules, parseError, status);
+ builder.fScanner->parse();
+ if (U_FAILURE(status)) { // status checked here bcos build below doesn't
+ return NULL;
+ }
+
+ //
+ // UnicodeSet processing.
+ // Munge the Unicode Sets to create a set of character categories.
+ // Generate the mapping tables (TRIE) from input 32-bit characters to
+ // the character categories.
+ //
+ builder.fSetBuilder->build();
+
+
+ //
+ // Generate the DFA state transition table.
+ //
+ builder.fForwardTables = new RBBITableBuilder(&builder, &builder.fForwardTree);
+ builder.fReverseTables = new RBBITableBuilder(&builder, &builder.fReverseTree);
+ builder.fSafeFwdTables = new RBBITableBuilder(&builder, &builder.fSafeFwdTree);
+ builder.fSafeRevTables = new RBBITableBuilder(&builder, &builder.fSafeRevTree);
+ if (U_SUCCESS(status)
+ && (builder.fForwardTables == NULL || builder.fReverseTables == NULL ||
+ builder.fSafeFwdTables == NULL || builder.fSafeRevTables == NULL))
+ {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ builder.fForwardTables->build();
+ builder.fReverseTables->build();
+ builder.fSafeFwdTables->build();
+ builder.fSafeRevTables->build();
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+#ifdef RBBI_DEBUG
+ if (builder.fDebugEnv && uprv_strstr(builder.fDebugEnv, "states")) {
+ builder.fForwardTables->printRuleStatusTable();
+ }
+#endif
+
+ //
+ // Package up the compiled data into a memory image
+ // in the run-time format.
+ //
+ RBBIDataHeader *data = builder.flattenData(); // returns NULL if error
+
+
+ //
+ // Clean up the compiler related stuff
+ //
+
+
+ //
+ // Create a break iterator from the compiled rules.
+ // (Identical to creation from stored pre-compiled rules)
+ //
+ // status is checked after init in construction.
+ RuleBasedBreakIterator *This = new RuleBasedBreakIterator(data, status);
+ if (U_FAILURE(status)) {
+ delete This;
+ This = NULL;
+ }
+ else if(This == NULL) { // test for NULL
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return This;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbirb.h b/Build/source/libs/icu/icu-xetex/common/rbbirb.h
new file mode 100644
index 00000000000..d7a5383606c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbirb.h
@@ -0,0 +1,211 @@
+//
+// rbbirb.h
+//
+// Copyright (C) 2002-2005, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains declarations for several classes from the
+// Rule Based Break Iterator rule builder.
+//
+
+
+#ifndef RBBIRB_H
+#define RBBIRB_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/rbbi.h"
+#include "unicode/uniset.h"
+#include "unicode/parseerr.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "unicode/symtable.h"// For UnicodeSet parsing, is the interface that
+ // looks up references to $variables within a set.
+
+
+
+U_NAMESPACE_BEGIN
+
+class RBBIRuleScanner;
+struct RBBIRuleTableEl;
+class RBBISetBuilder;
+class RBBINode;
+class RBBITableBuilder;
+
+
+
+//--------------------------------------------------------------------------------
+//
+// RBBISymbolTable. Implements SymbolTable interface that is used by the
+// UnicodeSet parser to resolve references to $variables.
+//
+//--------------------------------------------------------------------------------
+class RBBISymbolTableEntry : public UMemory { // The symbol table hash table contains one
+public: // of these structs for each entry.
+ RBBISymbolTableEntry();
+ UnicodeString key;
+ RBBINode *val;
+ ~RBBISymbolTableEntry();
+
+private:
+ RBBISymbolTableEntry(const RBBISymbolTableEntry &other); // forbid copying of this class
+ RBBISymbolTableEntry &operator=(const RBBISymbolTableEntry &other); // forbid copying of this class
+};
+
+
+class RBBISymbolTable : public UMemory, public SymbolTable {
+private:
+ const UnicodeString &fRules;
+ UHashtable *fHashTable;
+ RBBIRuleScanner *fRuleScanner;
+
+ // These next two fields are part of the mechanism for passing references to
+ // already-constructed UnicodeSets back to the UnicodeSet constructor
+ // when the pattern includes $variable references.
+ const UnicodeString ffffString; // = "/uffff"
+ UnicodeSet *fCachedSetLookup;
+
+public:
+ // API inherited from class SymbolTable
+ virtual const UnicodeString* lookup(const UnicodeString& s) const;
+ virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const;
+ virtual UnicodeString parseReference(const UnicodeString& text,
+ ParsePosition& pos, int32_t limit) const;
+
+ // Additional Functions
+ RBBISymbolTable(RBBIRuleScanner *, const UnicodeString &fRules, UErrorCode &status);
+ virtual ~RBBISymbolTable();
+
+ virtual RBBINode *lookupNode(const UnicodeString &key) const;
+ virtual void addEntry (const UnicodeString &key, RBBINode *val, UErrorCode &err);
+
+#ifdef RBBI_DEBUG
+ virtual void rbbiSymtablePrint() const;
+#else
+ // A do-nothing inline function for non-debug builds. Member funcs can't be empty
+ // or the call sites won't compile.
+ int32_t fFakeField;
+ #define rbbiSymtablePrint() fFakeField=0;
+#endif
+
+private:
+ RBBISymbolTable(const RBBISymbolTable &other); // forbid copying of this class
+ RBBISymbolTable &operator=(const RBBISymbolTable &other); // forbid copying of this class
+};
+
+
+//--------------------------------------------------------------------------------
+//
+// class RBBIRuleBuilder The top-level class handling RBBI rule compiling.
+//
+//--------------------------------------------------------------------------------
+class RBBIRuleBuilder : public UMemory {
+public:
+
+ // Create a rule based break iterator from a set of rules.
+ // This function is the main entry point into the rule builder. The
+ // public ICU API for creating RBBIs uses this function to do the actual work.
+ //
+ static BreakIterator * createRuleBasedBreakIterator( const UnicodeString &rules,
+ UParseError &parseError,
+ UErrorCode &status);
+
+public:
+ // The "public" functions and data members that appear below are accessed
+ // (and shared) by the various parts that make up the rule builder. They
+ // are NOT intended to be accessed by anything outside of the
+ // rule builder implementation.
+ RBBIRuleBuilder(const UnicodeString &rules,
+ UParseError &parseErr,
+ UErrorCode &status
+ );
+
+ virtual ~RBBIRuleBuilder();
+ char *fDebugEnv; // controls debug trace output
+ UErrorCode *fStatus; // Error reporting. Keeping status
+ UParseError *fParseError; // here avoids passing it everywhere.
+ const UnicodeString &fRules; // The rule string that we are compiling
+
+ RBBIRuleScanner *fScanner; // The scanner.
+ RBBINode *fForwardTree; // The parse trees, generated by the scanner,
+ RBBINode *fReverseTree; // then manipulated by subsequent steps.
+ RBBINode *fSafeFwdTree;
+ RBBINode *fSafeRevTree;
+
+ RBBINode **fDefaultTree; // For rules not qualified with a !
+ // the tree to which they belong to.
+
+ UBool fChainRules; // True for chained Unicode TR style rules.
+ // False for traditional regexp rules.
+
+ UBool fLBCMNoChain; // True: suppress chaining of rules on
+ // chars with LineBreak property == CM.
+
+ UBool fLookAheadHardBreak; // True: Look ahead matches cause an
+ // immediate break, no continuing for the
+ // longest match.
+
+ RBBISetBuilder *fSetBuilder; // Set and Character Category builder.
+ UVector *fUSetNodes; // Vector of all uset nodes.
+
+ RBBITableBuilder *fForwardTables; // State transition tables
+ RBBITableBuilder *fReverseTables;
+ RBBITableBuilder *fSafeFwdTables;
+ RBBITableBuilder *fSafeRevTables;
+
+ UVector *fRuleStatusVals; // The values that can be returned
+ // from getRuleStatus().
+
+ RBBIDataHeader *flattenData(); // Create the flattened (runtime format)
+ // data tables..
+private:
+ RBBIRuleBuilder(const RBBIRuleBuilder &other); // forbid copying of this class
+ RBBIRuleBuilder &operator=(const RBBIRuleBuilder &other); // forbid copying of this class
+};
+
+
+
+
+//----------------------------------------------------------------------------
+//
+// RBBISetTableEl is an entry in the hash table of UnicodeSets that have
+// been encountered. The val Node will be of nodetype uset
+// and contain pointers to the actual UnicodeSets.
+// The Key is the source string for initializing the set.
+//
+// The hash table is used to avoid creating duplicate
+// unnamed (not $var references) UnicodeSets.
+//
+// Memory Management:
+// The Hash Table owns these RBBISetTableEl structs and
+// the key strings. It does NOT own the val nodes.
+//
+//----------------------------------------------------------------------------
+struct RBBISetTableEl {
+ UnicodeString *key;
+ RBBINode *val;
+};
+
+
+//----------------------------------------------------------------------------
+//
+// RBBIDebugPrintf Printf equivalent, for debugging output.
+// Conditional compilation of the implementation lets us
+// get rid of the stdio dependency in environments where it
+// is unavailable.
+//
+//----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+#include
+#define RBBIDebugPrintf printf
+#define RBBIDebugPuts puts
+#else
+#undef RBBIDebugPrintf
+#define RBBIDebugPuts(arg)
+#endif
+
+U_NAMESPACE_END
+#endif
+
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbirpt.h b/Build/source/libs/icu/icu-xetex/common/rbbirpt.h
new file mode 100644
index 00000000000..deea57b7add
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbirpt.h
@@ -0,0 +1,275 @@
+//---------------------------------------------------------------------------------
+//
+// Generated Header File. Do not edit by hand.
+// This file contains the state table for the ICU Rule Based Break Iterator
+// rule parser.
+// It is generated by the Perl script "rbbicst.pl" from
+// the rule parser state definitions file "rbbirpt.txt".
+//
+// Copyright (C) 2002-2005 International Business Machines Corporation
+// and others. All rights reserved.
+//
+//---------------------------------------------------------------------------------
+#ifndef RBBIRPT_H
+#define RBBIRPT_H
+
+U_NAMESPACE_BEGIN
+//
+// Character classes for RBBI rule scanning.
+//
+ static const uint8_t kRuleSet_digit_char = 128;
+ static const uint8_t kRuleSet_name_char = 129;
+ static const uint8_t kRuleSet_name_start_char = 130;
+ static const uint8_t kRuleSet_rule_char = 131;
+ static const uint8_t kRuleSet_white_space = 132;
+
+
+enum RBBI_RuleParseAction {
+ doCheckVarDef,
+ doDotAny,
+ doEndAssign,
+ doEndOfRule,
+ doEndVariableName,
+ doExit,
+ doExprCatOperator,
+ doExprFinished,
+ doExprOrOperator,
+ doExprRParen,
+ doExprStart,
+ doLParen,
+ doNOP,
+ doOptionEnd,
+ doOptionStart,
+ doReverseDir,
+ doRuleChar,
+ doRuleError,
+ doRuleErrorAssignExpr,
+ doScanUnicodeSet,
+ doSlash,
+ doStartAssign,
+ doStartTagValue,
+ doStartVariableName,
+ doTagDigit,
+ doTagExpectedError,
+ doTagValue,
+ doUnaryOpPlus,
+ doUnaryOpQuestion,
+ doUnaryOpStar,
+ doVariableNameExpectedErr,
+ rbbiLastAction};
+
+//-------------------------------------------------------------------------------
+//
+// RBBIRuleTableEl represents the structure of a row in the transition table
+// for the rule parser state machine.
+//-------------------------------------------------------------------------------
+struct RBBIRuleTableEl {
+ RBBI_RuleParseAction fAction;
+ uint8_t fCharClass; // 0-127: an individual ASCII character
+ // 128-255: character class index
+ uint8_t fNextState; // 0-250: normal next-stat numbers
+ // 255: pop next-state from stack.
+ uint8_t fPushState;
+ UBool fNextChar;
+};
+
+static const struct RBBIRuleTableEl gRuleParseStateTable[] = {
+ {doNOP, 0, 0, 0, TRUE}
+ , {doExprStart, 254, 21, 8, FALSE} // 1 start
+ , {doNOP, 132, 1,0, TRUE} // 2
+ , {doExprStart, 36 /* $ */, 80, 90, FALSE} // 3
+ , {doNOP, 33 /* ! */, 11,0, TRUE} // 4
+ , {doNOP, 59 /* ; */, 1,0, TRUE} // 5
+ , {doNOP, 252, 0,0, FALSE} // 6
+ , {doExprStart, 255, 21, 8, FALSE} // 7
+ , {doEndOfRule, 59 /* ; */, 1,0, TRUE} // 8 break-rule-end
+ , {doNOP, 132, 8,0, TRUE} // 9
+ , {doRuleError, 255, 95,0, FALSE} // 10
+ , {doNOP, 33 /* ! */, 13,0, TRUE} // 11 rev-option
+ , {doReverseDir, 255, 20, 8, FALSE} // 12
+ , {doOptionStart, 130, 15,0, TRUE} // 13 option-scan1
+ , {doRuleError, 255, 95,0, FALSE} // 14
+ , {doNOP, 129, 15,0, TRUE} // 15 option-scan2
+ , {doOptionEnd, 255, 17,0, FALSE} // 16
+ , {doNOP, 59 /* ; */, 1,0, TRUE} // 17 option-scan3
+ , {doNOP, 132, 17,0, TRUE} // 18
+ , {doRuleError, 255, 95,0, FALSE} // 19
+ , {doExprStart, 255, 21, 8, FALSE} // 20 reverse-rule
+ , {doRuleChar, 254, 30,0, TRUE} // 21 term
+ , {doNOP, 132, 21,0, TRUE} // 22
+ , {doRuleChar, 131, 30,0, TRUE} // 23
+ , {doNOP, 91 /* [ */, 86, 30, FALSE} // 24
+ , {doLParen, 40 /* ( */, 21, 30, TRUE} // 25
+ , {doNOP, 36 /* $ */, 80, 29, FALSE} // 26
+ , {doDotAny, 46 /* . */, 30,0, TRUE} // 27
+ , {doRuleError, 255, 95,0, FALSE} // 28
+ , {doCheckVarDef, 255, 30,0, FALSE} // 29 term-var-ref
+ , {doNOP, 132, 30,0, TRUE} // 30 expr-mod
+ , {doUnaryOpStar, 42 /* * */, 35,0, TRUE} // 31
+ , {doUnaryOpPlus, 43 /* + */, 35,0, TRUE} // 32
+ , {doUnaryOpQuestion, 63 /* ? */, 35,0, TRUE} // 33
+ , {doNOP, 255, 35,0, FALSE} // 34
+ , {doExprCatOperator, 254, 21,0, FALSE} // 35 expr-cont
+ , {doNOP, 132, 35,0, TRUE} // 36
+ , {doExprCatOperator, 131, 21,0, FALSE} // 37
+ , {doExprCatOperator, 91 /* [ */, 21,0, FALSE} // 38
+ , {doExprCatOperator, 40 /* ( */, 21,0, FALSE} // 39
+ , {doExprCatOperator, 36 /* $ */, 21,0, FALSE} // 40
+ , {doExprCatOperator, 46 /* . */, 21,0, FALSE} // 41
+ , {doExprCatOperator, 47 /* / */, 47,0, FALSE} // 42
+ , {doExprCatOperator, 123 /* { */, 59,0, TRUE} // 43
+ , {doExprOrOperator, 124 /* | */, 21,0, TRUE} // 44
+ , {doExprRParen, 41 /* ) */, 255,0, TRUE} // 45
+ , {doExprFinished, 255, 255,0, FALSE} // 46
+ , {doSlash, 47 /* / */, 49,0, TRUE} // 47 look-ahead
+ , {doNOP, 255, 95,0, FALSE} // 48
+ , {doExprCatOperator, 254, 21,0, FALSE} // 49 expr-cont-no-slash
+ , {doNOP, 132, 35,0, TRUE} // 50
+ , {doExprCatOperator, 131, 21,0, FALSE} // 51
+ , {doExprCatOperator, 91 /* [ */, 21,0, FALSE} // 52
+ , {doExprCatOperator, 40 /* ( */, 21,0, FALSE} // 53
+ , {doExprCatOperator, 36 /* $ */, 21,0, FALSE} // 54
+ , {doExprCatOperator, 46 /* . */, 21,0, FALSE} // 55
+ , {doExprOrOperator, 124 /* | */, 21,0, TRUE} // 56
+ , {doExprRParen, 41 /* ) */, 255,0, TRUE} // 57
+ , {doExprFinished, 255, 255,0, FALSE} // 58
+ , {doNOP, 132, 59,0, TRUE} // 59 tag-open
+ , {doStartTagValue, 128, 62,0, FALSE} // 60
+ , {doTagExpectedError, 255, 95,0, FALSE} // 61
+ , {doNOP, 132, 66,0, TRUE} // 62 tag-value
+ , {doNOP, 125 /* } */, 66,0, FALSE} // 63
+ , {doTagDigit, 128, 62,0, TRUE} // 64
+ , {doTagExpectedError, 255, 95,0, FALSE} // 65
+ , {doNOP, 132, 66,0, TRUE} // 66 tag-close
+ , {doTagValue, 125 /* } */, 69,0, TRUE} // 67
+ , {doTagExpectedError, 255, 95,0, FALSE} // 68
+ , {doExprCatOperator, 254, 21,0, FALSE} // 69 expr-cont-no-tag
+ , {doNOP, 132, 69,0, TRUE} // 70
+ , {doExprCatOperator, 131, 21,0, FALSE} // 71
+ , {doExprCatOperator, 91 /* [ */, 21,0, FALSE} // 72
+ , {doExprCatOperator, 40 /* ( */, 21,0, FALSE} // 73
+ , {doExprCatOperator, 36 /* $ */, 21,0, FALSE} // 74
+ , {doExprCatOperator, 46 /* . */, 21,0, FALSE} // 75
+ , {doExprCatOperator, 47 /* / */, 47,0, FALSE} // 76
+ , {doExprOrOperator, 124 /* | */, 21,0, TRUE} // 77
+ , {doExprRParen, 41 /* ) */, 255,0, TRUE} // 78
+ , {doExprFinished, 255, 255,0, FALSE} // 79
+ , {doStartVariableName, 36 /* $ */, 82,0, TRUE} // 80 scan-var-name
+ , {doNOP, 255, 95,0, FALSE} // 81
+ , {doNOP, 130, 84,0, TRUE} // 82 scan-var-start
+ , {doVariableNameExpectedErr, 255, 95,0, FALSE} // 83
+ , {doNOP, 129, 84,0, TRUE} // 84 scan-var-body
+ , {doEndVariableName, 255, 255,0, FALSE} // 85
+ , {doScanUnicodeSet, 91 /* [ */, 255,0, TRUE} // 86 scan-unicode-set
+ , {doScanUnicodeSet, 112 /* p */, 255,0, TRUE} // 87
+ , {doScanUnicodeSet, 80 /* P */, 255,0, TRUE} // 88
+ , {doNOP, 255, 95,0, FALSE} // 89
+ , {doNOP, 132, 90,0, TRUE} // 90 assign-or-rule
+ , {doStartAssign, 61 /* = */, 21, 93, TRUE} // 91
+ , {doNOP, 255, 29, 8, FALSE} // 92
+ , {doEndAssign, 59 /* ; */, 1,0, TRUE} // 93 assign-end
+ , {doRuleErrorAssignExpr, 255, 95,0, FALSE} // 94
+ , {doExit, 255, 95,0, TRUE} // 95 errorDeath
+ };
+#ifdef RBBI_DEBUG
+static const char * const RBBIRuleStateNames[] = { 0,
+ "start",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "break-rule-end",
+ 0,
+ 0,
+ "rev-option",
+ 0,
+ "option-scan1",
+ 0,
+ "option-scan2",
+ 0,
+ "option-scan3",
+ 0,
+ 0,
+ "reverse-rule",
+ "term",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "term-var-ref",
+ "expr-mod",
+ 0,
+ 0,
+ 0,
+ 0,
+ "expr-cont",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "look-ahead",
+ 0,
+ "expr-cont-no-slash",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "tag-open",
+ 0,
+ 0,
+ "tag-value",
+ 0,
+ 0,
+ 0,
+ "tag-close",
+ 0,
+ 0,
+ "expr-cont-no-tag",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "scan-var-name",
+ 0,
+ "scan-var-start",
+ 0,
+ "scan-var-body",
+ 0,
+ "scan-unicode-set",
+ 0,
+ 0,
+ 0,
+ "assign-or-rule",
+ 0,
+ 0,
+ "assign-end",
+ 0,
+ "errorDeath",
+ 0};
+#endif
+
+U_NAMESPACE_END
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbirpt.txt b/Build/source/libs/icu/icu-xetex/common/rbbirpt.txt
new file mode 100644
index 00000000000..8e932a6037a
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbirpt.txt
@@ -0,0 +1,315 @@
+
+#*****************************************************************************
+#
+# Copyright (C) 2002-2003, International Business Machines Corporation and others.
+# All Rights Reserved.
+#
+#*****************************************************************************
+#
+# file: rbbirpt.txt
+# ICU Break Iterator Rule Parser State Table
+#
+# This state table is used when reading and parsing a set of RBBI rules
+# The rule parser uses a state machine; the data in this file define the
+# state transitions that occur for each input character.
+#
+# *** This file defines the RBBI rule grammar. This is it.
+# *** The determination of what is accepted is here.
+#
+# This file is processed by a perl script "rbbicst.pl" to produce initialized C arrays
+# that are then built with the rule parser.
+#
+
+#
+# Here is the syntax of the state definitions in this file:
+#
+#
+#StateName:
+# input-char n next-state ^push-state action
+# input-char n next-state ^push-state action
+# | | | | |
+# | | | | |--- action to be performed by state machine
+# | | | | See function RBBIRuleScanner::doParseActions()
+# | | | |
+# | | | |--- Push this named state onto the state stack.
+# | | | Later, when next state is specified as "pop",
+# | | | the pushed state will become the current state.
+# | | |
+# | | |--- Transition to this state if the current input character matches the input
+# | | character or char class in the left hand column. "pop" causes the next
+# | | state to be popped from the state stack.
+# | |
+# | |--- When making the state transition specified on this line, advance to the next
+# | character from the input only if 'n' appears here.
+# |
+# |--- Character or named character classes to test for. If the current character being scanned
+# matches, peform the actions and go to the state specified on this line.
+# The input character is tested sequentally, in the order written. The characters and
+# character classes tested for do not need to be mutually exclusive. The first match wins.
+#
+
+
+
+
+#
+# start state, scan position is at the beginning of the rules file, or in between two rules.
+#
+start:
+ escaped term ^break-rule-end doExprStart
+ white_space n start
+ '$' scan-var-name ^assign-or-rule doExprStart
+ '!' n rev-option
+ ';' n start # ignore empty rules.
+ eof exit
+ default term ^break-rule-end doExprStart
+
+#
+# break-rule-end: Returned from doing a break-rule expression.
+#
+break-rule-end:
+ ';' n start doEndOfRule
+ white_space n break-rule-end
+ default errorDeath doRuleError
+
+
+#
+# ! We've just scanned a '!', indicating either a !!key word flag or a
+# !Reverse rule.
+#
+rev-option:
+ '!' n option-scan1
+ default reverse-rule ^break-rule-end doReverseDir
+
+option-scan1:
+ name_start_char n option-scan2 doOptionStart
+ default errorDeath doRuleError
+
+option-scan2:
+ name_char n option-scan2
+ default option-scan3 doOptionEnd
+
+option-scan3:
+ ';' n start
+ white_space n option-scan3
+ default errorDeath doRuleError
+
+
+reverse-rule:
+ default term ^break-rule-end doExprStart
+
+
+#
+# term. Eat through a single rule character, or a composite thing, which
+# could be a parenthesized expression, a variable name, or a Unicode Set.
+#
+term:
+ escaped n expr-mod doRuleChar
+ white_space n term
+ rule_char n expr-mod doRuleChar
+ '[' scan-unicode-set ^expr-mod
+ '(' n term ^expr-mod doLParen
+ '$' scan-var-name ^term-var-ref
+ '.' n expr-mod doDotAny
+ default errorDeath doRuleError
+
+
+
+#
+# term-var-ref We've just finished scanning a reference to a $variable.
+# Check that the variable was defined.
+# The variable name scanning is in common with assignment statements,
+# so the check can't be done there.
+term-var-ref:
+ default expr-mod doCheckVarDef
+
+
+#
+# expr-mod We've just finished scanning a term, now look for the optional
+# trailing '*', '?', '+'
+#
+expr-mod:
+ white_space n expr-mod
+ '*' n expr-cont doUnaryOpStar
+ '+' n expr-cont doUnaryOpPlus
+ '?' n expr-cont doUnaryOpQuestion
+ default expr-cont
+
+
+#
+# expr-cont Expression, continuation. At a point where additional terms are
+# allowed, but not required.
+#
+expr-cont:
+ escaped term doExprCatOperator
+ white_space n expr-cont
+ rule_char term doExprCatOperator
+ '[' term doExprCatOperator
+ '(' term doExprCatOperator
+ '$' term doExprCatOperator
+ '.' term doExprCatOperator
+ '/' look-ahead doExprCatOperator
+ '{' n tag-open doExprCatOperator
+ '|' n term doExprOrOperator
+ ')' n pop doExprRParen
+ default pop doExprFinished
+
+
+#
+# look-ahead Scanning a '/', which identifies a break point, assuming that the
+# remainder of the expression matches.
+#
+# Generate a parse tree as if this was a special kind of input symbol
+# appearing in an otherwise normal concatenation expression.
+#
+look-ahead:
+ '/' n expr-cont-no-slash doSlash
+ default errorDeath
+
+
+#
+# expr-cont-no-slash Expression, continuation. At a point where additional terms are
+# allowed, but not required. Just like
+# expr-cont, above, except that no '/'
+# look-ahead symbol is permitted.
+#
+expr-cont-no-slash:
+ escaped term doExprCatOperator
+ white_space n expr-cont
+ rule_char term doExprCatOperator
+ '[' term doExprCatOperator
+ '(' term doExprCatOperator
+ '$' term doExprCatOperator
+ '.' term doExprCatOperator
+ '|' n term doExprOrOperator
+ ')' n pop doExprRParen
+ default pop doExprFinished
+
+
+#
+# tags scanning a '{', the opening delimiter for a tag that identifies
+# the kind of match. Scan the whole {dddd} tag, where d=digit
+#
+tag-open:
+ white_space n tag-open
+ digit_char tag-value doStartTagValue
+ default errorDeath doTagExpectedError
+
+tag-value:
+ white_space n tag-close
+ '}' tag-close
+ digit_char n tag-value doTagDigit
+ default errorDeath doTagExpectedError
+
+tag-close:
+ white_space n tag-close
+ '}' n expr-cont-no-tag doTagValue
+ default errorDeath doTagExpectedError
+
+
+
+#
+# expr-cont-no-tag Expression, continuation. At a point where additional terms are
+# allowed, but not required. Just like
+# expr-cont, above, except that no "{ddd}"
+# tagging is permitted.
+#
+expr-cont-no-tag:
+ escaped term doExprCatOperator
+ white_space n expr-cont-no-tag
+ rule_char term doExprCatOperator
+ '[' term doExprCatOperator
+ '(' term doExprCatOperator
+ '$' term doExprCatOperator
+ '.' term doExprCatOperator
+ '/' look-ahead doExprCatOperator
+ '|' n term doExprOrOperator
+ ')' n pop doExprRParen
+ default pop doExprFinished
+
+
+
+
+#
+# Variable Name Scanning.
+#
+# The state that branched to here must have pushed a return state
+# to go to after completion of the variable name scanning.
+#
+# The current input character must be the $ that introduces the name.
+# The $ is consummed here rather than in the state that first detected it
+# so that the doStartVariableName action only needs to happen in one
+# place (here), and the other states don't need to worry about it.
+#
+scan-var-name:
+ '$' n scan-var-start doStartVariableName
+ default errorDeath
+
+
+scan-var-start:
+ name_start_char n scan-var-body
+ default errorDeath doVariableNameExpectedErr
+
+scan-var-body:
+ name_char n scan-var-body
+ default pop doEndVariableName
+
+
+
+#
+# scan-unicode-set Unicode Sets are parsed by the the UnicodeSet class.
+# Within the RBBI parser, after finding the first character
+# of a Unicode Set, we just hand the rule input at that
+# point of to the Unicode Set constructor, then pick
+# up parsing after the close of the set.
+#
+# The action for this state invokes the UnicodeSet parser.
+#
+scan-unicode-set:
+ '[' n pop doScanUnicodeSet
+ 'p' n pop doScanUnicodeSet
+ 'P' n pop doScanUnicodeSet
+ default errorDeath
+
+
+
+
+
+
+
+#
+# assign-or-rule. A $variable was encountered at the start of something, could be
+# either an assignment statement or a rule, depending on whether an '='
+# follows the variable name. We get to this state when the variable name
+# scanning does a return.
+#
+assign-or-rule:
+ white_space n assign-or-rule
+ '=' n term ^assign-end doStartAssign # variable was target of assignment
+ default term-var-ref ^break-rule-end # variable was a term in a rule
+
+
+
+#
+# assign-end This state is entered when the end of the expression on the
+# right hand side of an assignment is found. We get here via
+# a pop; this state is pushed when the '=' in an assignment is found.
+#
+# The only thing allowed at this point is a ';'. The RHS of an
+# assignment must look like a rule expression, and we come here
+# when what is being scanned no longer looks like an expression.
+#
+assign-end:
+ ';' n start doEndAssign
+ default errorDeath doRuleErrorAssignExpr
+
+
+
+#
+# errorDeath. This state is specified as the next state whenever a syntax error
+# in the source rules is detected. Barring bugs, the state machine will never
+# actually get here, but will stop because of the action associated with the error.
+# But, just in case, this state asks the state machine to exit.
+errorDeath:
+ default n errorDeath doExit
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbiscan.cpp b/Build/source/libs/icu/icu-xetex/common/rbbiscan.cpp
new file mode 100644
index 00000000000..2d5c5ec1f02
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbiscan.cpp
@@ -0,0 +1,1193 @@
+
+//
+// file: rbbiscan.cpp
+//
+// Copyright (C) 2002-2007, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains the Rule Based Break Iterator Rule Builder functions for
+// scanning the rules and assembling a parse tree. This is the first phase
+// of compiling the rules.
+//
+// The overall of the rules is managed by class RBBIRuleBuilder, which will
+// create and use an instance of this class as part of the process.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/uchriter.h"
+#include "unicode/parsepos.h"
+#include "unicode/parseerr.h"
+#include "util.h"
+#include "cmemory.h"
+#include "cstring.h"
+
+#include "rbbirpt.h" // Contains state table for the rbbi rules parser.
+ // generated by a Perl script.
+#include "rbbirb.h"
+#include "rbbinode.h"
+#include "rbbiscan.h"
+#include "rbbitblb.h"
+
+#include "uassert.h"
+
+
+//----------------------------------------------------------------------------------------
+//
+// Unicode Set init strings for each of the character classes needed for parsing a rule file.
+// (Initialized with hex values for portability to EBCDIC based machines.
+// Really ugly, but there's no good way to avoid it.)
+//
+// The sets are referred to by name in the rbbirpt.txt, which is the
+// source form of the state transition table for the RBBI rule parser.
+//
+//----------------------------------------------------------------------------------------
+static const UChar gRuleSet_rule_char_pattern[] = {
+ // [ ^ [ \ p { Z } \ u 0 0 2 0
+ 0x5b, 0x5e, 0x5b, 0x5c, 0x70, 0x7b, 0x5a, 0x7d, 0x5c, 0x75, 0x30, 0x30, 0x32, 0x30,
+ // - \ u 0 0 7 f ] - [ \ p
+ 0x2d, 0x5c, 0x75, 0x30, 0x30, 0x37, 0x66, 0x5d, 0x2d, 0x5b, 0x5c, 0x70,
+ // { L } ] - [ \ p { N } ] ]
+ 0x7b, 0x4c, 0x7d, 0x5d, 0x2d, 0x5b, 0x5c, 0x70, 0x7b, 0x4e, 0x7d, 0x5d, 0x5d, 0};
+
+static const UChar gRuleSet_name_char_pattern[] = {
+// [ _ \ p { L } \ p { N } ]
+ 0x5b, 0x5f, 0x5c, 0x70, 0x7b, 0x4c, 0x7d, 0x5c, 0x70, 0x7b, 0x4e, 0x7d, 0x5d, 0};
+
+static const UChar gRuleSet_digit_char_pattern[] = {
+// [ 0 - 9 ]
+ 0x5b, 0x30, 0x2d, 0x39, 0x5d, 0};
+
+static const UChar gRuleSet_name_start_char_pattern[] = {
+// [ _ \ p { L } ]
+ 0x5b, 0x5f, 0x5c, 0x70, 0x7b, 0x4c, 0x7d, 0x5d, 0 };
+
+static const UChar kAny[] = {0x61, 0x6e, 0x79, 0x00}; // "any"
+
+
+U_CDECL_BEGIN
+static void U_CALLCONV RBBISetTable_deleter(void *p) {
+ U_NAMESPACE_QUALIFIER RBBISetTableEl *px = (U_NAMESPACE_QUALIFIER RBBISetTableEl *)p;
+ delete px->key;
+ // Note: px->val is owned by the linked list "fSetsListHead" in scanner.
+ // Don't delete the value nodes here.
+ uprv_free(px);
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+//----------------------------------------------------------------------------------------
+//
+// Constructor.
+//
+//----------------------------------------------------------------------------------------
+RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
+{
+ fRB = rb;
+ fStackPtr = 0;
+ fStack[fStackPtr] = 0;
+ fNodeStackPtr = 0;
+ fRuleNum = 0;
+ fNodeStack[0] = NULL;
+
+ fRuleSets[kRuleSet_rule_char-128] = NULL;
+ fRuleSets[kRuleSet_white_space-128] = NULL;
+ fRuleSets[kRuleSet_name_char-128] = NULL;
+ fRuleSets[kRuleSet_name_start_char-128] = NULL;
+ fRuleSets[kRuleSet_digit_char-128] = NULL;
+ fSymbolTable = NULL;
+ fSetTable = NULL;
+
+ fScanIndex = 0;
+ fNextIndex = 0;
+
+ fReverseRule = FALSE;
+ fLookAheadRule = FALSE;
+
+ fLineNum = 1;
+ fCharNum = 0;
+ fQuoteMode = FALSE;
+
+ // Do not check status until after all critical fields are sufficiently initialized
+ // that the destructor can run cleanly.
+ if (U_FAILURE(*rb->fStatus)) {
+ return;
+ }
+
+ //
+ // Set up the constant Unicode Sets.
+ // Note: These could be made static, lazily initialized, and shared among
+ // all instances of RBBIRuleScanners. BUT this is quite a bit simpler,
+ // and the time to build these few sets should be small compared to a
+ // full break iterator build.
+ fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(gRuleSet_rule_char_pattern, *rb->fStatus);
+ fRuleSets[kRuleSet_white_space-128] = uprv_openRuleWhiteSpaceSet(rb->fStatus);
+ fRuleSets[kRuleSet_name_char-128] = new UnicodeSet(gRuleSet_name_char_pattern, *rb->fStatus);
+ fRuleSets[kRuleSet_name_start_char-128] = new UnicodeSet(gRuleSet_name_start_char_pattern, *rb->fStatus);
+ fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(gRuleSet_digit_char_pattern, *rb->fStatus);
+ if (*rb->fStatus == U_ILLEGAL_ARGUMENT_ERROR) {
+ // This case happens if ICU's data is missing. UnicodeSet tries to look up property
+ // names from the init string, can't find them, and claims an illegal arguement.
+ // Change the error so that the actual problem will be clearer to users.
+ *rb->fStatus = U_BRK_INIT_ERROR;
+ }
+ if (U_FAILURE(*rb->fStatus)) {
+ return;
+ }
+
+ fSymbolTable = new RBBISymbolTable(this, rb->fRules, *rb->fStatus);
+ fSetTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, rb->fStatus);
+ uhash_setValueDeleter(fSetTable, RBBISetTable_deleter);
+}
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// Destructor
+//
+//----------------------------------------------------------------------------------------
+RBBIRuleScanner::~RBBIRuleScanner() {
+ delete fRuleSets[kRuleSet_rule_char-128];
+ delete fRuleSets[kRuleSet_white_space-128];
+ delete fRuleSets[kRuleSet_name_char-128];
+ delete fRuleSets[kRuleSet_name_start_char-128];
+ delete fRuleSets[kRuleSet_digit_char-128];
+
+ delete fSymbolTable;
+ if (fSetTable != NULL) {
+ uhash_close(fSetTable);
+ fSetTable = NULL;
+
+ }
+
+
+ // Node Stack.
+ // Normally has one entry, which is the entire parse tree for the rules.
+ // If errors occured, there may be additional subtrees left on the stack.
+ while (fNodeStackPtr > 0) {
+ delete fNodeStack[fNodeStackPtr];
+ fNodeStackPtr--;
+ }
+
+}
+
+//----------------------------------------------------------------------------------------
+//
+// doParseAction Do some action during rule parsing.
+// Called by the parse state machine.
+// Actions build the parse tree and Unicode Sets,
+// and maintain the parse stack for nested expressions.
+//
+// TODO: unify EParseAction and RBBI_RuleParseAction enum types.
+// They represent exactly the same thing. They're separate
+// only to work around enum forward declaration restrictions
+// in some compilers, while at the same time avoiding multiple
+// definitions problems. I'm sure that there's a better way.
+//
+//----------------------------------------------------------------------------------------
+UBool RBBIRuleScanner::doParseActions(int32_t action)
+{
+ RBBINode *n = NULL;
+
+ UBool returnVal = TRUE;
+
+ switch (action) {
+
+ case doExprStart:
+ pushNewNode(RBBINode::opStart);
+ fRuleNum++;
+ break;
+
+
+ case doExprOrOperator:
+ {
+ fixOpStack(RBBINode::precOpCat);
+ RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
+ RBBINode *orNode = pushNewNode(RBBINode::opOr);
+ orNode->fLeftChild = operandNode;
+ operandNode->fParent = orNode;
+ }
+ break;
+
+ case doExprCatOperator:
+ // concatenation operator.
+ // For the implicit concatenation of adjacent terms in an expression that are
+ // not separated by any other operator. Action is invoked between the
+ // actions for the two terms.
+ {
+ fixOpStack(RBBINode::precOpCat);
+ RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
+ RBBINode *catNode = pushNewNode(RBBINode::opCat);
+ catNode->fLeftChild = operandNode;
+ operandNode->fParent = catNode;
+ }
+ break;
+
+ case doLParen:
+ // Open Paren.
+ // The openParen node is a dummy operation type with a low precedence,
+ // which has the affect of ensuring that any real binary op that
+ // follows within the parens binds more tightly to the operands than
+ // stuff outside of the parens.
+ pushNewNode(RBBINode::opLParen);
+ break;
+
+ case doExprRParen:
+ fixOpStack(RBBINode::precLParen);
+ break;
+
+ case doNOP:
+ break;
+
+ case doStartAssign:
+ // We've just scanned "$variable = "
+ // The top of the node stack has the $variable ref node.
+
+ // Save the start position of the RHS text in the StartExpression node
+ // that precedes the $variableReference node on the stack.
+ // This will eventually be used when saving the full $variable replacement
+ // text as a string.
+ n = fNodeStack[fNodeStackPtr-1];
+ n->fFirstPos = fNextIndex; // move past the '='
+
+ // Push a new start-of-expression node; needed to keep parse of the
+ // RHS expression happy.
+ pushNewNode(RBBINode::opStart);
+ break;
+
+
+
+
+ case doEndAssign:
+ {
+ // We have reached the end of an assignement statement.
+ // Current scan char is the ';' that terminates the assignment.
+
+ // Terminate expression, leaves expression parse tree rooted in TOS node.
+ fixOpStack(RBBINode::precStart);
+
+ RBBINode *startExprNode = fNodeStack[fNodeStackPtr-2];
+ RBBINode *varRefNode = fNodeStack[fNodeStackPtr-1];
+ RBBINode *RHSExprNode = fNodeStack[fNodeStackPtr];
+
+ // Save original text of right side of assignment, excluding the terminating ';'
+ // in the root of the node for the right-hand-side expression.
+ RHSExprNode->fFirstPos = startExprNode->fFirstPos;
+ RHSExprNode->fLastPos = fScanIndex;
+ fRB->fRules.extractBetween(RHSExprNode->fFirstPos, RHSExprNode->fLastPos, RHSExprNode->fText);
+
+ // Expression parse tree becomes l. child of the $variable reference node.
+ varRefNode->fLeftChild = RHSExprNode;
+ RHSExprNode->fParent = varRefNode;
+
+ // Make a symbol table entry for the $variableRef node.
+ fSymbolTable->addEntry(varRefNode->fText, varRefNode, *fRB->fStatus);
+ if (U_FAILURE(*fRB->fStatus)) {
+ // This is a round-about way to get the parse position set
+ // so that duplicate symbols error messages include a line number.
+ UErrorCode t = *fRB->fStatus;
+ *fRB->fStatus = U_ZERO_ERROR;
+ error(t);
+ }
+
+ // Clean up the stack.
+ delete startExprNode;
+ fNodeStackPtr-=3;
+ break;
+ }
+
+ case doEndOfRule:
+ {
+ fixOpStack(RBBINode::precStart); // Terminate expression, leaves expression
+ if (U_FAILURE(*fRB->fStatus)) { // parse tree rooted in TOS node.
+ break;
+ }
+#ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "rtree")) {printNodeStack("end of rule");}
+#endif
+ U_ASSERT(fNodeStackPtr == 1);
+
+ // If this rule includes a look-ahead '/', add a endMark node to the
+ // expression tree.
+ if (fLookAheadRule) {
+ RBBINode *thisRule = fNodeStack[fNodeStackPtr];
+ RBBINode *endNode = pushNewNode(RBBINode::endMark);
+ RBBINode *catNode = pushNewNode(RBBINode::opCat);
+ fNodeStackPtr -= 2;
+ catNode->fLeftChild = thisRule;
+ catNode->fRightChild = endNode;
+ fNodeStack[fNodeStackPtr] = catNode;
+ endNode->fVal = fRuleNum;
+ endNode->fLookAheadEnd = TRUE;
+ }
+
+ // All rule expressions are ORed together.
+ // The ';' that terminates an expression really just functions as a '|' with
+ // a low operator prededence.
+ //
+ // Each of the four sets of rules are collected separately.
+ // (forward, reverse, safe_forward, safe_reverse)
+ // OR this rule into the appropriate group of them.
+ //
+ RBBINode **destRules = (fReverseRule? &fRB->fReverseTree : fRB->fDefaultTree);
+
+ if (*destRules != NULL) {
+ // This is not the first rule encounted.
+ // OR previous stuff (from *destRules)
+ // with the current rule expression (on the Node Stack)
+ // with the resulting OR expression going to *destRules
+ //
+ RBBINode *thisRule = fNodeStack[fNodeStackPtr];
+ RBBINode *prevRules = *destRules;
+ RBBINode *orNode = pushNewNode(RBBINode::opOr);
+ orNode->fLeftChild = prevRules;
+ prevRules->fParent = orNode;
+ orNode->fRightChild = thisRule;
+ thisRule->fParent = orNode;
+ *destRules = orNode;
+ }
+ else
+ {
+ // This is the first rule encountered (for this direction).
+ // Just move its parse tree from the stack to *destRules.
+ *destRules = fNodeStack[fNodeStackPtr];
+ }
+ fReverseRule = FALSE; // in preparation for the next rule.
+ fLookAheadRule = FALSE;
+ fNodeStackPtr = 0;
+ }
+ break;
+
+
+ case doRuleError:
+ error(U_BRK_RULE_SYNTAX);
+ returnVal = FALSE;
+ break;
+
+
+ case doVariableNameExpectedErr:
+ error(U_BRK_RULE_SYNTAX);
+ break;
+
+
+ //
+ // Unary operands + ? *
+ // These all appear after the operand to which they apply.
+ // When we hit one, the operand (may be a whole sub expression)
+ // will be on the top of the stack.
+ // Unary Operator becomes TOS, with the old TOS as its one child.
+ case doUnaryOpPlus:
+ {
+ RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
+ RBBINode *plusNode = pushNewNode(RBBINode::opPlus);
+ plusNode->fLeftChild = operandNode;
+ operandNode->fParent = plusNode;
+ }
+ break;
+
+ case doUnaryOpQuestion:
+ {
+ RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
+ RBBINode *qNode = pushNewNode(RBBINode::opQuestion);
+ qNode->fLeftChild = operandNode;
+ operandNode->fParent = qNode;
+ }
+ break;
+
+ case doUnaryOpStar:
+ {
+ RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
+ RBBINode *starNode = pushNewNode(RBBINode::opStar);
+ starNode->fLeftChild = operandNode;
+ operandNode->fParent = starNode;
+ }
+ break;
+
+ case doRuleChar:
+ // A "Rule Character" is any single character that is a literal part
+ // of the regular expression. Like a, b and c in the expression "(abc*) | [:L:]"
+ // These are pretty uncommon in break rules; the terms are more commonly
+ // sets. To keep things uniform, treat these characters like as
+ // sets that just happen to contain only one character.
+ {
+ n = pushNewNode(RBBINode::setRef);
+ findSetFor(fC.fChar, n);
+ n->fFirstPos = fScanIndex;
+ n->fLastPos = fNextIndex;
+ fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
+ break;
+ }
+
+ case doDotAny:
+ // scanned a ".", meaning match any single character.
+ {
+ n = pushNewNode(RBBINode::setRef);
+ findSetFor(kAny, n);
+ n->fFirstPos = fScanIndex;
+ n->fLastPos = fNextIndex;
+ fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
+ break;
+ }
+
+ case doSlash:
+ // Scanned a '/', which identifies a look-ahead break position in a rule.
+ n = pushNewNode(RBBINode::lookAhead);
+ n->fVal = fRuleNum;
+ n->fFirstPos = fScanIndex;
+ n->fLastPos = fNextIndex;
+ fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
+ fLookAheadRule = TRUE;
+ break;
+
+
+ case doStartTagValue:
+ // Scanned a '{', the opening delimiter for a tag value within a rule.
+ n = pushNewNode(RBBINode::tag);
+ n->fVal = 0;
+ n->fFirstPos = fScanIndex;
+ n->fLastPos = fNextIndex;
+ break;
+
+ case doTagDigit:
+ // Just scanned a decimal digit that's part of a tag value
+ {
+ n = fNodeStack[fNodeStackPtr];
+ uint32_t v = u_charDigitValue(fC.fChar);
+ U_ASSERT(v < 10);
+ n->fVal = n->fVal*10 + v;
+ break;
+ }
+
+ case doTagValue:
+ n = fNodeStack[fNodeStackPtr];
+ n->fLastPos = fNextIndex;
+ fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
+ break;
+
+ case doTagExpectedError:
+ error(U_BRK_MALFORMED_RULE_TAG);
+ returnVal = FALSE;
+ break;
+
+ case doOptionStart:
+ // Scanning a !!option. At the start of string.
+ fOptionStart = fScanIndex;
+ break;
+
+ case doOptionEnd:
+ {
+ UnicodeString opt(fRB->fRules, fOptionStart, fScanIndex-fOptionStart);
+ if (opt == UNICODE_STRING("chain", 5)) {
+ fRB->fChainRules = TRUE;
+ } else if (opt == UNICODE_STRING("LBCMNoChain", 11)) {
+ fRB->fLBCMNoChain = TRUE;
+ } else if (opt == UNICODE_STRING("forward", 7)) {
+ fRB->fDefaultTree = &fRB->fForwardTree;
+ } else if (opt == UNICODE_STRING("reverse", 7)) {
+ fRB->fDefaultTree = &fRB->fReverseTree;
+ } else if (opt == UNICODE_STRING("safe_forward", 12)) {
+ fRB->fDefaultTree = &fRB->fSafeFwdTree;
+ } else if (opt == UNICODE_STRING("safe_reverse", 12)) {
+ fRB->fDefaultTree = &fRB->fSafeRevTree;
+ } else if (opt == UNICODE_STRING("lookAheadHardBreak", 18)) {
+ fRB->fLookAheadHardBreak = TRUE;
+ } else {
+ error(U_BRK_UNRECOGNIZED_OPTION);
+ }
+ }
+ break;
+
+ case doReverseDir:
+ fReverseRule = TRUE;
+ break;
+
+ case doStartVariableName:
+ n = pushNewNode(RBBINode::varRef);
+ if (U_FAILURE(*fRB->fStatus)) {
+ break;
+ }
+ n->fFirstPos = fScanIndex;
+ break;
+
+ case doEndVariableName:
+ n = fNodeStack[fNodeStackPtr];
+ if (n==NULL || n->fType != RBBINode::varRef) {
+ error(U_BRK_INTERNAL_ERROR);
+ break;
+ }
+ n->fLastPos = fScanIndex;
+ fRB->fRules.extractBetween(n->fFirstPos+1, n->fLastPos, n->fText);
+ // Look the newly scanned name up in the symbol table
+ // If there's an entry, set the l. child of the var ref to the replacement expression.
+ // (We also pass through here when scanning assignments, but no harm is done, other
+ // than a slight wasted effort that seems hard to avoid. Lookup will be null)
+ n->fLeftChild = fSymbolTable->lookupNode(n->fText);
+ break;
+
+ case doCheckVarDef:
+ n = fNodeStack[fNodeStackPtr];
+ if (n->fLeftChild == NULL) {
+ error(U_BRK_UNDEFINED_VARIABLE);
+ returnVal = FALSE;
+ }
+ break;
+
+ case doExprFinished:
+ break;
+
+ case doRuleErrorAssignExpr:
+ error(U_BRK_ASSIGN_ERROR);
+ returnVal = FALSE;
+ break;
+
+ case doExit:
+ returnVal = FALSE;
+ break;
+
+ case doScanUnicodeSet:
+ scanSet();
+ break;
+
+ default:
+ error(U_BRK_INTERNAL_ERROR);
+ returnVal = FALSE;
+ break;
+ }
+ return returnVal;
+}
+
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// Error Report a rule parse error.
+// Only report it if no previous error has been recorded.
+//
+//----------------------------------------------------------------------------------------
+void RBBIRuleScanner::error(UErrorCode e) {
+ if (U_SUCCESS(*fRB->fStatus)) {
+ *fRB->fStatus = e;
+ fRB->fParseError->line = fLineNum;
+ fRB->fParseError->offset = fCharNum;
+ fRB->fParseError->preContext[0] = 0;
+ fRB->fParseError->preContext[0] = 0;
+ }
+}
+
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// fixOpStack The parse stack holds partially assembled chunks of the parse tree.
+// An entry on the stack may be as small as a single setRef node,
+// or as large as the parse tree
+// for an entire expression (this will be the one item left on the stack
+// when the parsing of an RBBI rule completes.
+//
+// This function is called when a binary operator is encountered.
+// It looks back up the stack for operators that are not yet associated
+// with a right operand, and if the precedence of the stacked operator >=
+// the precedence of the current operator, binds the operand left,
+// to the previously encountered operator.
+//
+//----------------------------------------------------------------------------------------
+void RBBIRuleScanner::fixOpStack(RBBINode::OpPrecedence p) {
+ RBBINode *n;
+ // printNodeStack("entering fixOpStack()");
+ for (;;) {
+ n = fNodeStack[fNodeStackPtr-1]; // an operator node
+ if (n->fPrecedence == 0) {
+ RBBIDebugPuts("RBBIRuleScanner::fixOpStack, bad operator node");
+ error(U_BRK_INTERNAL_ERROR);
+ return;
+ }
+
+ if (n->fPrecedence < p || n->fPrecedence <= RBBINode::precLParen) {
+ // The most recent operand goes with the current operator,
+ // not with the previously stacked one.
+ break;
+ }
+ // Stack operator is a binary op ( '|' or concatenation)
+ // TOS operand becomes right child of this operator.
+ // Resulting subexpression becomes the TOS operand.
+ n->fRightChild = fNodeStack[fNodeStackPtr];
+ fNodeStack[fNodeStackPtr]->fParent = n;
+ fNodeStackPtr--;
+ // printNodeStack("looping in fixOpStack() ");
+ }
+
+ if (p <= RBBINode::precLParen) {
+ // Scan is at a right paren or end of expression.
+ // The scanned item must match the stack, or else there was an error.
+ // Discard the left paren (or start expr) node from the stack,
+ // leaving the completed (sub)expression as TOS.
+ if (n->fPrecedence != p) {
+ // Right paren encountered matched start of expression node, or
+ // end of expression matched with a left paren node.
+ error(U_BRK_MISMATCHED_PAREN);
+ }
+ fNodeStack[fNodeStackPtr-1] = fNodeStack[fNodeStackPtr];
+ fNodeStackPtr--;
+ // Delete the now-discarded LParen or Start node.
+ delete n;
+ }
+ // printNodeStack("leaving fixOpStack()");
+}
+
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// findSetFor given a UnicodeString,
+// - find the corresponding Unicode Set (uset node)
+// (create one if necessary)
+// - Set fLeftChild of the caller's node (should be a setRef node)
+// to the uset node
+// Maintain a hash table of uset nodes, so the same one is always used
+// for the same string.
+// If a "to adopt" set is provided and we haven't seen this key before,
+// add the provided set to the hash table.
+// If the string is one (32 bit) char in length, the set contains
+// just one element which is the char in question.
+// If the string is "any", return a set containing all chars.
+//
+//----------------------------------------------------------------------------------------
+void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt) {
+
+ RBBISetTableEl *el;
+
+ // First check whether we've already cached a set for this string.
+ // If so, just use the cached set in the new node.
+ // delete any set provided by the caller, since we own it.
+ el = (RBBISetTableEl *)uhash_get(fSetTable, &s);
+ if (el != NULL) {
+ delete setToAdopt;
+ node->fLeftChild = el->val;
+ U_ASSERT(node->fLeftChild->fType == RBBINode::uset);
+ return;
+ }
+
+ // Haven't seen this set before.
+ // If the caller didn't provide us with a prebuilt set,
+ // create a new UnicodeSet now.
+ if (setToAdopt == NULL) {
+ if (s.compare(kAny, -1) == 0) {
+ setToAdopt = new UnicodeSet(0x000000, 0x10ffff);
+ } else {
+ UChar32 c;
+ c = s.char32At(0);
+ setToAdopt = new UnicodeSet(c, c);
+ }
+ }
+
+ //
+ // Make a new uset node to refer to this UnicodeSet
+ // This new uset node becomes the child of the caller's setReference node.
+ //
+ RBBINode *usetNode = new RBBINode(RBBINode::uset);
+ usetNode->fInputSet = setToAdopt;
+ usetNode->fParent = node;
+ node->fLeftChild = usetNode;
+ usetNode->fText = s;
+
+
+ //
+ // Add the new uset node to the list of all uset nodes.
+ //
+ fRB->fUSetNodes->addElement(usetNode, *fRB->fStatus);
+
+
+ //
+ // Add the new set to the set hash table.
+ //
+ el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl));
+ UnicodeString *tkey = new UnicodeString(s);
+ if (tkey == NULL || el == NULL || setToAdopt == NULL) {
+ error(U_MEMORY_ALLOCATION_ERROR);
+ return;
+ }
+ el->key = tkey;
+ el->val = usetNode;
+ uhash_put(fSetTable, el->key, el, fRB->fStatus);
+
+ return;
+}
+
+
+
+//
+// Assorted Unicode character constants.
+// Numeric because there is no portable way to enter them as literals.
+// (Think EBCDIC).
+//
+static const UChar chCR = 0x0d; // New lines, for terminating comments.
+static const UChar chLF = 0x0a;
+static const UChar chNEL = 0x85; // NEL newline variant
+static const UChar chLS = 0x2028; // Unicode Line Separator
+static const UChar chApos = 0x27; // single quote, for quoted chars.
+static const UChar chPound = 0x23; // '#', introduces a comment.
+static const UChar chBackSlash = 0x5c; // '\' introduces a char escape
+static const UChar chLParen = 0x28;
+static const UChar chRParen = 0x29;
+
+
+//----------------------------------------------------------------------------------------
+//
+// stripRules Return a rules string without unnecessary
+// characters.
+//
+//----------------------------------------------------------------------------------------
+UnicodeString RBBIRuleScanner::stripRules(const UnicodeString &rules) {
+ UnicodeString strippedRules;
+ int rulesLength = rules.length();
+ for (int idx = 0; idx < rulesLength; ) {
+ UChar ch = rules[idx++];
+ if (ch == chPound) {
+ while (idx < rulesLength
+ && ch != chCR && ch != chLF && ch != chNEL)
+ {
+ ch = rules[idx++];
+ }
+ }
+ if (!u_isISOControl(ch)) {
+ strippedRules.append(ch);
+ }
+ }
+ // strippedRules = strippedRules.unescape();
+ return strippedRules;
+}
+
+
+//----------------------------------------------------------------------------------------
+//
+// nextCharLL Low Level Next Char from rule input source.
+// Get a char from the input character iterator,
+// keep track of input position for error reporting.
+//
+//----------------------------------------------------------------------------------------
+UChar32 RBBIRuleScanner::nextCharLL() {
+ UChar32 ch;
+
+ if (fNextIndex >= fRB->fRules.length()) {
+ return (UChar32)-1;
+ }
+ ch = fRB->fRules.char32At(fNextIndex);
+ fNextIndex = fRB->fRules.moveIndex32(fNextIndex, 1);
+
+ if (ch == chCR ||
+ ch == chNEL ||
+ ch == chLS ||
+ ch == chLF && fLastChar != chCR) {
+ // Character is starting a new line. Bump up the line number, and
+ // reset the column to 0.
+ fLineNum++;
+ fCharNum=0;
+ if (fQuoteMode) {
+ error(U_BRK_NEW_LINE_IN_QUOTED_STRING);
+ fQuoteMode = FALSE;
+ }
+ }
+ else {
+ // Character is not starting a new line. Except in the case of a
+ // LF following a CR, increment the column position.
+ if (ch != chLF) {
+ fCharNum++;
+ }
+ }
+ fLastChar = ch;
+ return ch;
+}
+
+
+//---------------------------------------------------------------------------------
+//
+// nextChar for rules scanning. At this level, we handle stripping
+// out comments and processing backslash character escapes.
+// The rest of the rules grammar is handled at the next level up.
+//
+//---------------------------------------------------------------------------------
+void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
+
+ // Unicode Character constants needed for the processing done by nextChar(),
+ // in hex because literals wont work on EBCDIC machines.
+
+ fScanIndex = fNextIndex;
+ c.fChar = nextCharLL();
+ c.fEscaped = FALSE;
+
+ //
+ // check for '' sequence.
+ // These are recognized in all contexts, whether in quoted text or not.
+ //
+ if (c.fChar == chApos) {
+ if (fRB->fRules.char32At(fNextIndex) == chApos) {
+ c.fChar = nextCharLL(); // get nextChar officially so character counts
+ c.fEscaped = TRUE; // stay correct.
+ }
+ else
+ {
+ // Single quote, by itself.
+ // Toggle quoting mode.
+ // Return either '(' or ')', because quotes cause a grouping of the quoted text.
+ fQuoteMode = !fQuoteMode;
+ if (fQuoteMode == TRUE) {
+ c.fChar = chLParen;
+ } else {
+ c.fChar = chRParen;
+ }
+ c.fEscaped = FALSE; // The paren that we return is not escaped.
+ return;
+ }
+ }
+
+ if (fQuoteMode) {
+ c.fEscaped = TRUE;
+ }
+ else
+ {
+ // We are not in a 'quoted region' of the source.
+ //
+ if (c.fChar == chPound) {
+ // Start of a comment. Consume the rest of it.
+ // The new-line char that terminates the comment is always returned.
+ // It will be treated as white-space, and serves to break up anything
+ // that might otherwise incorrectly clump together with a comment in
+ // the middle (a variable name, for example.)
+ for (;;) {
+ c.fChar = nextCharLL();
+ if (c.fChar == (UChar32)-1 || // EOF
+ c.fChar == chCR ||
+ c.fChar == chLF ||
+ c.fChar == chNEL ||
+ c.fChar == chLS) {break;}
+ }
+ }
+ if (c.fChar == (UChar32)-1) {
+ return;
+ }
+
+ //
+ // check for backslash escaped characters.
+ // Use UnicodeString::unescapeAt() to handle them.
+ //
+ if (c.fChar == chBackSlash) {
+ c.fEscaped = TRUE;
+ int32_t startX = fNextIndex;
+ c.fChar = fRB->fRules.unescapeAt(fNextIndex);
+ if (fNextIndex == startX) {
+ error(U_BRK_HEX_DIGITS_EXPECTED);
+ }
+ fCharNum += fNextIndex-startX;
+ }
+ }
+ // putc(c.fChar, stdout);
+}
+
+//---------------------------------------------------------------------------------
+//
+// Parse RBBI rules. The state machine for rules parsing is here.
+// The state tables are hand-written in the file rbbirpt.txt,
+// and converted to the form used here by a perl
+// script rbbicst.pl
+//
+//---------------------------------------------------------------------------------
+void RBBIRuleScanner::parse() {
+ uint16_t state;
+ const RBBIRuleTableEl *tableEl;
+
+ if (U_FAILURE(*fRB->fStatus)) {
+ return;
+ }
+
+ state = 1;
+ nextChar(fC);
+ //
+ // Main loop for the rule parsing state machine.
+ // Runs once per state transition.
+ // Each time through optionally performs, depending on the state table,
+ // - an advance to the the next input char
+ // - an action to be performed.
+ // - pushing or popping a state to/from the local state return stack.
+ //
+ for (;;) {
+ // Bail out if anything has gone wrong.
+ // RBBI rule file parsing stops on the first error encountered.
+ if (U_FAILURE(*fRB->fStatus)) {
+ break;
+ }
+
+ // Quit if state == 0. This is the normal way to exit the state machine.
+ //
+ if (state == 0) {
+ break;
+ }
+
+ // Find the state table element that matches the input char from the rule, or the
+ // class of the input character. Start with the first table row for this
+ // state, then linearly scan forward until we find a row that matches the
+ // character. The last row for each state always matches all characters, so
+ // the search will stop there, if not before.
+ //
+ tableEl = &gRuleParseStateTable[state];
+ #ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) {
+ RBBIDebugPrintf("char, line, col = (\'%c\', %d, %d) state=%s ",
+ fC.fChar, fLineNum, fCharNum, RBBIRuleStateNames[state]);
+ }
+ #endif
+
+ for (;;) {
+ #ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf(".");}
+ #endif
+ if (tableEl->fCharClass < 127 && fC.fEscaped == FALSE && tableEl->fCharClass == fC.fChar) {
+ // Table row specified an individual character, not a set, and
+ // the input character is not escaped, and
+ // the input character matched it.
+ break;
+ }
+ if (tableEl->fCharClass == 255) {
+ // Table row specified default, match anything character class.
+ break;
+ }
+ if (tableEl->fCharClass == 254 && fC.fEscaped) {
+ // Table row specified "escaped" and the char was escaped.
+ break;
+ }
+ if (tableEl->fCharClass == 253 && fC.fEscaped &&
+ (fC.fChar == 0x50 || fC.fChar == 0x70 )) {
+ // Table row specified "escaped P" and the char is either 'p' or 'P'.
+ break;
+ }
+ if (tableEl->fCharClass == 252 && fC.fChar == (UChar32)-1) {
+ // Table row specified eof and we hit eof on the input.
+ break;
+ }
+
+ if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
+ fC.fEscaped == FALSE && // char is not escaped &&
+ fC.fChar != (UChar32)-1) { // char is not EOF
+ UnicodeSet *uniset = fRuleSets[tableEl->fCharClass-128];
+ if (uniset->contains(fC.fChar)) {
+ // Table row specified a character class, or set of characters,
+ // and the current char matches it.
+ break;
+ }
+ }
+
+ // No match on this row, advance to the next row for this state,
+ tableEl++;
+ }
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPuts("");}
+
+ //
+ // We've found the row of the state table that matches the current input
+ // character from the rules string.
+ // Perform any action specified by this row in the state table.
+ if (doParseActions((int32_t)tableEl->fAction) == FALSE) {
+ // Break out of the state machine loop if the
+ // the action signalled some kind of error, or
+ // the action was to exit, occurs on normal end-of-rules-input.
+ break;
+ }
+
+ if (tableEl->fPushState != 0) {
+ fStackPtr++;
+ if (fStackPtr >= kStackSize) {
+ error(U_BRK_INTERNAL_ERROR);
+ RBBIDebugPuts("RBBIRuleScanner::parse() - state stack overflow.");
+ fStackPtr--;
+ }
+ fStack[fStackPtr] = tableEl->fPushState;
+ }
+
+ if (tableEl->fNextChar) {
+ nextChar(fC);
+ }
+
+ // Get the next state from the table entry, or from the
+ // state stack if the next state was specified as "pop".
+ if (tableEl->fNextState != 255) {
+ state = tableEl->fNextState;
+ } else {
+ state = fStack[fStackPtr];
+ fStackPtr--;
+ if (fStackPtr < 0) {
+ error(U_BRK_INTERNAL_ERROR);
+ RBBIDebugPuts("RBBIRuleScanner::parse() - state stack underflow.");
+ fStackPtr++;
+ }
+ }
+
+ }
+
+ //
+ // If there were NO user specified reverse rules, set up the equivalent of ".*;"
+ //
+ if (fRB->fReverseTree == NULL) {
+ fRB->fReverseTree = pushNewNode(RBBINode::opStar);
+ RBBINode *operand = pushNewNode(RBBINode::setRef);
+ findSetFor(kAny, operand);
+ fRB->fReverseTree->fLeftChild = operand;
+ operand->fParent = fRB->fReverseTree;
+ fNodeStackPtr -= 2;
+ }
+
+
+ //
+ // Parsing of the input RBBI rules is complete.
+ // We now have a parse tree for the rule expressions
+ // and a list of all UnicodeSets that are referenced.
+ //
+#ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->rbbiSymtablePrint();}
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ptree"))
+ {
+ RBBIDebugPrintf("Completed Forward Rules Parse Tree...\n");
+ fRB->fForwardTree->printTree(TRUE);
+ RBBIDebugPrintf("\nCompleted Reverse Rules Parse Tree...\n");
+ fRB->fReverseTree->printTree(TRUE);
+ RBBIDebugPrintf("\nCompleted Safe Point Forward Rules Parse Tree...\n");
+ fRB->fSafeFwdTree->printTree(TRUE);
+ RBBIDebugPrintf("\nCompleted Safe Point Reverse Rules Parse Tree...\n");
+ fRB->fSafeRevTree->printTree(TRUE);
+ }
+#endif
+}
+
+
+//---------------------------------------------------------------------------------
+//
+// printNodeStack for debugging...
+//
+//---------------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBIRuleScanner::printNodeStack(const char *title) {
+ int i;
+ RBBIDebugPrintf("%s. Dumping node stack...\n", title);
+ for (i=fNodeStackPtr; i>0; i--) {fNodeStack[i]->printTree(TRUE);}
+}
+#endif
+
+
+
+
+//---------------------------------------------------------------------------------
+//
+// pushNewNode create a new RBBINode of the specified type and push it
+// onto the stack of nodes.
+//
+//---------------------------------------------------------------------------------
+RBBINode *RBBIRuleScanner::pushNewNode(RBBINode::NodeType t) {
+ fNodeStackPtr++;
+ if (fNodeStackPtr >= kStackSize) {
+ error(U_BRK_INTERNAL_ERROR);
+ RBBIDebugPuts("RBBIRuleScanner::pushNewNode - stack overflow.");
+ *fRB->fStatus = U_BRK_INTERNAL_ERROR;
+ return NULL;
+ }
+ fNodeStack[fNodeStackPtr] = new RBBINode(t);
+ if (fNodeStack[fNodeStackPtr] == NULL) {
+ *fRB->fStatus = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return fNodeStack[fNodeStackPtr];
+}
+
+
+
+//---------------------------------------------------------------------------------
+//
+// scanSet Construct a UnicodeSet from the text at the current scan
+// position. Advance the scan position to the first character
+// after the set.
+//
+// A new RBBI setref node referring to the set is pushed onto the node
+// stack.
+//
+// The scan position is normally under the control of the state machine
+// that controls rule parsing. UnicodeSets, however, are parsed by
+// the UnicodeSet constructor, not by the RBBI rule parser.
+//
+//---------------------------------------------------------------------------------
+void RBBIRuleScanner::scanSet() {
+ UnicodeSet *uset;
+ ParsePosition pos;
+ int startPos;
+ int i;
+
+ if (U_FAILURE(*fRB->fStatus)) {
+ return;
+ }
+
+ pos.setIndex(fScanIndex);
+ startPos = fScanIndex;
+ UErrorCode localStatus = U_ZERO_ERROR;
+ uset = new UnicodeSet(fRB->fRules, pos, USET_IGNORE_SPACE,
+ fSymbolTable,
+ localStatus);
+ if (U_FAILURE(localStatus)) {
+ // TODO: Get more accurate position of the error from UnicodeSet's return info.
+ // UnicodeSet appears to not be reporting correctly at this time.
+ #ifdef RBBI_DEBUG
+ RBBIDebugPrintf("UnicodeSet parse postion.ErrorIndex = %d\n", pos.getIndex());
+ #endif
+ error(localStatus);
+ delete uset;
+ return;
+ }
+
+ // Verify that the set contains at least one code point.
+ //
+ if (uset->isEmpty()) {
+ // This set is empty.
+ // Make it an error, because it almost certainly is not what the user wanted.
+ // Also, avoids having to think about corner cases in the tree manipulation code
+ // that occurs later on.
+ error(U_BRK_RULE_EMPTY_SET);
+ delete uset;
+ return;
+ }
+
+
+ // Advance the RBBI parse postion over the UnicodeSet pattern.
+ // Don't just set fScanIndex because the line/char positions maintained
+ // for error reporting would be thrown off.
+ i = pos.getIndex();
+ for (;;) {
+ if (fNextIndex >= i) {
+ break;
+ }
+ nextCharLL();
+ }
+
+ if (U_SUCCESS(*fRB->fStatus)) {
+ RBBINode *n;
+
+ n = pushNewNode(RBBINode::setRef);
+ n->fFirstPos = startPos;
+ n->fLastPos = fNextIndex;
+ fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);
+ // findSetFor() serves several purposes here:
+ // - Adopts storage for the UnicodeSet, will be responsible for deleting.
+ // - Mantains collection of all sets in use, needed later for establishing
+ // character categories for run time engine.
+ // - Eliminates mulitiple instances of the same set.
+ // - Creates a new uset node if necessary (if this isn't a duplicate.)
+ findSetFor(n->fText, n, uset);
+ }
+
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbiscan.h b/Build/source/libs/icu/icu-xetex/common/rbbiscan.h
new file mode 100644
index 00000000000..cd0bf94a4fb
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbiscan.h
@@ -0,0 +1,160 @@
+//
+// rbbiscan.h
+//
+// Copyright (C) 2002-2007, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains declarations for class RBBIRuleScanner
+//
+
+
+#ifndef RBBISCAN_H
+#define RBBISCAN_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/rbbi.h"
+#include "unicode/uniset.h"
+#include "unicode/parseerr.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "unicode/symtable.h"// For UnicodeSet parsing, is the interface that
+ // looks up references to $variables within a set.
+#include "rbbinode.h"
+//#include "rbbitblb.h"
+
+
+
+U_NAMESPACE_BEGIN
+
+class RBBIRuleBuilder;
+class RBBISymbolTable;
+
+
+//--------------------------------------------------------------------------------
+//
+// class RBBIRuleScanner does the lowest level, character-at-a-time
+// scanning of break iterator rules.
+//
+// The output of the scanner is parse trees for
+// the rule expressions and a list of all Unicode Sets
+// encountered.
+//
+//--------------------------------------------------------------------------------
+static const int kStackSize = 100; // The size of the state stack for
+ // rules parsing. Corresponds roughly
+ // to the depth of parentheses nesting
+ // that is allowed in the rules.
+
+class RBBIRuleScanner : public UMemory {
+public:
+
+ struct RBBIRuleChar {
+ UChar32 fChar;
+ UBool fEscaped;
+ };
+
+ RBBIRuleScanner(RBBIRuleBuilder *rb);
+
+
+ virtual ~RBBIRuleScanner();
+
+ void nextChar(RBBIRuleChar &c); // Get the next char from the input stream.
+ // Return false if at end.
+
+ UBool push(const RBBIRuleChar &c); // Push (unget) one character.
+ // Only a single character may be pushed.
+
+ void parse(); // Parse the rules, generating two parse
+ // trees, one each for the forward and
+ // reverse rules,
+ // and a list of UnicodeSets encountered.
+
+ /**
+ * Return a rules string without unnecessary
+ * characters.
+ */
+ static UnicodeString stripRules(const UnicodeString &rules);
+private:
+
+ UBool doParseActions(int32_t a);
+ void error(UErrorCode e); // error reporting convenience function.
+ void fixOpStack(RBBINode::OpPrecedence p);
+ // a character.
+ void findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt = NULL);
+
+ UChar32 nextCharLL();
+#ifdef RBBI_DEBUG
+ void printNodeStack(const char *title);
+#endif
+ RBBINode *pushNewNode(RBBINode::NodeType t);
+ void scanSet();
+
+
+ RBBIRuleBuilder *fRB; // The rule builder that we are part of.
+
+ int32_t fScanIndex; // Index of current character being processed
+ // in the rule input string.
+ int32_t fNextIndex; // Index of the next character, which
+ // is the first character not yet scanned.
+ UBool fQuoteMode; // Scan is in a 'quoted region'
+ int32_t fLineNum; // Line number in input file.
+ int32_t fCharNum; // Char position within the line.
+ UChar32 fLastChar; // Previous char, needed to count CR-LF
+ // as a single line, not two.
+
+ RBBIRuleChar fC; // Current char for parse state machine
+ // processing.
+ UnicodeString fVarName; // $variableName, valid when we've just
+ // scanned one.
+
+ RBBIRuleTableEl **fStateTable; // State Transition Table for RBBI Rule
+ // parsing. index by p[state][char-class]
+
+ uint16_t fStack[kStackSize]; // State stack, holds state pushes
+ int32_t fStackPtr; // and pops as specified in the state
+ // transition rules.
+
+ RBBINode *fNodeStack[kStackSize]; // Node stack, holds nodes created
+ // during the parse of a rule
+ int32_t fNodeStackPtr;
+
+
+ UBool fReverseRule; // True if the rule currently being scanned
+ // is a reverse direction rule (if it
+ // starts with a '!')
+
+ UBool fLookAheadRule; // True if the rule includes a '/'
+ // somewhere within it.
+
+ RBBISymbolTable *fSymbolTable; // symbol table, holds definitions of
+ // $variable symbols.
+
+ UHashtable *fSetTable; // UnicocodeSet hash table, holds indexes to
+ // the sets created while parsing rules.
+ // The key is the string used for creating
+ // the set.
+
+ UnicodeSet *fRuleSets[10]; // Unicode Sets that are needed during
+ // the scanning of RBBI rules. The
+ // indicies for these are assigned by the
+ // perl script that builds the state tables.
+ // See rbbirpt.h.
+
+ int32_t fRuleNum; // Counts each rule as it is scanned.
+
+ int32_t fOptionStart; // Input index of start of a !!option
+ // keyword, while being scanned.
+
+ UnicodeSet *gRuleSet_rule_char;
+ UnicodeSet *gRuleSet_white_space;
+ UnicodeSet *gRuleSet_name_char;
+ UnicodeSet *gRuleSet_name_start_char;
+
+ RBBIRuleScanner(const RBBIRuleScanner &other); // forbid copying of this class
+ RBBIRuleScanner &operator=(const RBBIRuleScanner &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbisetb.cpp b/Build/source/libs/icu/icu-xetex/common/rbbisetb.cpp
new file mode 100644
index 00000000000..0bbe8e920ee
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbisetb.cpp
@@ -0,0 +1,684 @@
+//
+// rbbisetb.cpp
+//
+/*
+***************************************************************************
+* Copyright (C) 2002-2005 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+//
+// RBBISetBuilder Handles processing of Unicode Sets from RBBI rules
+// (part of the rule building process.)
+//
+// Starting with the rules parse tree from the scanner,
+//
+// - Enumerate the set of UnicodeSets that are referenced
+// by the RBBI rules.
+// - compute a set of non-overlapping character ranges
+// with all characters within a range belonging to the same
+// set of input uniocde sets.
+// - Derive a set of non-overlapping UnicodeSet (like things)
+// that will correspond to columns in the state table for
+// the RBBI execution engine. All characters within one
+// of these sets belong to the same set of the original
+// UnicodeSets from the user's rules.
+// - construct the trie table that maps input characters
+// to the index of the matching non-overlapping set of set from
+// the previous step.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/uniset.h"
+#include "utrie.h"
+#include "uvector.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "cstring.h"
+
+#include "rbbisetb.h"
+#include "rbbinode.h"
+
+
+//------------------------------------------------------------------------
+//
+// getFoldedRBBIValue Call-back function used during building of Trie table.
+// Folding value: just store the offset (16 bits)
+// if there is any non-0 entry.
+// (It'd really be nice if the Trie builder would provide a
+// simple default, so this function could go away from here.)
+//
+//------------------------------------------------------------------------
+/* folding value: just store the offset (16 bits) if there is any non-0 entry */
+U_CDECL_BEGIN
+static uint32_t U_CALLCONV
+getFoldedRBBIValue(UNewTrie *trie, UChar32 start, int32_t offset) {
+ uint32_t value;
+ UChar32 limit;
+ UBool inBlockZero;
+
+ limit=start+0x400;
+ while(startfStatus;
+ fRangeList = 0;
+ fTrie = 0;
+ fTrieSize = 0;
+ fGroupCount = 0;
+ fSawBOF = FALSE;
+}
+
+
+//------------------------------------------------------------------------
+//
+// Destructor
+//
+//------------------------------------------------------------------------
+RBBISetBuilder::~RBBISetBuilder()
+{
+ RangeDescriptor *nextRangeDesc;
+
+ // Walk through & delete the linked list of RangeDescriptors
+ for (nextRangeDesc = fRangeList; nextRangeDesc!=NULL;) {
+ RangeDescriptor *r = nextRangeDesc;
+ nextRangeDesc = r->fNext;
+ delete r;
+ }
+
+ utrie_close(fTrie);
+}
+
+
+
+
+//------------------------------------------------------------------------
+//
+// build Build the list of non-overlapping character ranges
+// from the Unicode Sets.
+//
+//------------------------------------------------------------------------
+void RBBISetBuilder::build() {
+ RBBINode *usetNode;
+ RangeDescriptor *rlRange;
+
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "usets")) {printSets();}
+
+ //
+ // Initialize the process by creating a single range encompassing all characters
+ // that is in no sets.
+ //
+ fRangeList = new RangeDescriptor(*fStatus); // will check for status here
+ fRangeList->fStartChar = 0;
+ fRangeList->fEndChar = 0x10ffff;
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ //
+ // Find the set of non-overlapping ranges of characters
+ //
+ int ni;
+ for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
+ usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
+ if (usetNode==NULL) {
+ break;
+ }
+
+ UnicodeSet *inputSet = usetNode->fInputSet;
+ int32_t inputSetRangeCount = inputSet->getRangeCount();
+ int inputSetRangeIndex = 0;
+ rlRange = fRangeList;
+
+ for (;;) {
+ if (inputSetRangeIndex >= inputSetRangeCount) {
+ break;
+ }
+ UChar32 inputSetRangeBegin = inputSet->getRangeStart(inputSetRangeIndex);
+ UChar32 inputSetRangeEnd = inputSet->getRangeEnd(inputSetRangeIndex);
+
+ // skip over ranges from the range list that are completely
+ // below the current range from the input unicode set.
+ while (rlRange->fEndChar < inputSetRangeBegin) {
+ rlRange = rlRange->fNext;
+ }
+
+ // If the start of the range from the range list is before with
+ // the start of the range from the unicode set, split the range list range
+ // in two, with one part being before (wholly outside of) the unicode set
+ // and the other containing the rest.
+ // Then continue the loop; the post-split current range will then be skipped
+ // over
+ if (rlRange->fStartChar < inputSetRangeBegin) {
+ rlRange->split(inputSetRangeBegin, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ continue;
+ }
+
+ // Same thing at the end of the ranges...
+ // If the end of the range from the range list doesn't coincide with
+ // the end of the range from the unicode set, split the range list
+ // range in two. The first part of the split range will be
+ // wholly inside the Unicode set.
+ if (rlRange->fEndChar > inputSetRangeEnd) {
+ rlRange->split(inputSetRangeEnd+1, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ }
+
+ // The current rlRange is now entirely within the UnicodeSet range.
+ // Add this unicode set to the list of sets for this rlRange
+ if (rlRange->fIncludesSets->indexOf(usetNode) == -1) {
+ rlRange->fIncludesSets->addElement(usetNode, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ }
+
+ // Advance over ranges that we are finished with.
+ if (inputSetRangeEnd == rlRange->fEndChar) {
+ inputSetRangeIndex++;
+ }
+ rlRange = rlRange->fNext;
+ }
+ }
+
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "range")) { printRanges();}
+
+ //
+ // Group the above ranges, with each group consisting of one or more
+ // ranges that are in exactly the same set of original UnicodeSets.
+ // The groups are numbered, and these group numbers are the set of
+ // input symbols recognized by the run-time state machine.
+ //
+ // Numbering: # 0 (state table column 0) is unused.
+ // # 1 is reserved - table column 1 is for end-of-input
+ // # 2 is reserved - table column 2 is for beginning-in-input
+ // # 3 is the first range list.
+ //
+ RangeDescriptor *rlSearchRange;
+ for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
+ for (rlSearchRange=fRangeList; rlSearchRange != rlRange; rlSearchRange=rlSearchRange->fNext) {
+ if (rlRange->fIncludesSets->equals(*rlSearchRange->fIncludesSets)) {
+ rlRange->fNum = rlSearchRange->fNum;
+ break;
+ }
+ }
+ if (rlRange->fNum == 0) {
+ fGroupCount ++;
+ rlRange->fNum = fGroupCount+2;
+ rlRange->setDictionaryFlag();
+ addValToSets(rlRange->fIncludesSets, fGroupCount+2);
+ }
+ }
+
+ // Handle input sets that contain the special string {eof}.
+ // Column 1 of the state table is reserved for EOF on input.
+ // Column 2 is reserved for before-the-start-input.
+ // (This column can be optimized away later if there are no rule
+ // references to {bof}.)
+ // Add this column value (1 or 2) to the equivalent expression
+ // subtree for each UnicodeSet that contains the string {eof}
+ // Because {bof} and {eof} are not a characters in the normal sense,
+ // they doesn't affect the computation of ranges or TRIE.
+ static const UChar eofUString[] = {0x65, 0x6f, 0x66, 0};
+ static const UChar bofUString[] = {0x62, 0x6f, 0x66, 0};
+
+ UnicodeString eofString(eofUString);
+ UnicodeString bofString(bofUString);
+ for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
+ usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
+ if (usetNode==NULL) {
+ break;
+ }
+ UnicodeSet *inputSet = usetNode->fInputSet;
+ if (inputSet->contains(eofString)) {
+ addValToSet(usetNode, 1);
+ }
+ if (inputSet->contains(bofString)) {
+ addValToSet(usetNode, 2);
+ fSawBOF = TRUE;
+ }
+ }
+
+
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "rgroup")) {printRangeGroups();}
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "esets")) {printSets();}
+
+ //
+ // Build the Trie table for mapping UChar32 values to the corresponding
+ // range group number
+ //
+ fTrie = utrie_open(NULL, // Pre-existing trie to be filled in
+ NULL, // Data array (utrie will allocate one)
+ 100000, // Max Data Length
+ 0, // Initial value for all code points
+ 0, // Lead surrogate unit value
+ TRUE); // Keep Latin 1 in separately
+
+
+ for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
+ utrie_setRange32(fTrie, rlRange->fStartChar, rlRange->fEndChar+1, rlRange->fNum, TRUE);
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------------
+//
+// getTrieSize() Return the size that will be required to serialize the Trie.
+//
+//-----------------------------------------------------------------------------------
+int32_t RBBISetBuilder::getTrieSize() /*const*/ {
+ fTrieSize = utrie_serialize(fTrie,
+ NULL, // Buffer
+ 0, // Capacity
+ getFoldedRBBIValue,
+ TRUE, // Reduce to 16 bits
+ fStatus);
+ // RBBIDebugPrintf("Trie table size is %d\n", trieSize);
+ return fTrieSize;
+}
+
+
+//-----------------------------------------------------------------------------------
+//
+// serializeTrie() Put the serialized trie at the specified address.
+// Trust the caller to have given us enough memory.
+// getTrieSize() MUST be called first.
+//
+//-----------------------------------------------------------------------------------
+void RBBISetBuilder::serializeTrie(uint8_t *where) {
+ utrie_serialize(fTrie,
+ where, // Buffer
+ fTrieSize, // Capacity
+ getFoldedRBBIValue,
+ TRUE, // Reduce to 16 bits
+ fStatus);
+}
+
+//------------------------------------------------------------------------
+//
+// addValToSets Add a runtime-mapped input value to each uset from a
+// list of uset nodes. (val corresponds to a state table column.)
+// For each of the original Unicode sets - which correspond
+// directly to uset nodes - a logically equivalent expression
+// is constructed in terms of the remapped runtime input
+// symbol set. This function adds one runtime input symbol to
+// a list of sets.
+//
+// The "logically equivalent expression" is the tree for an
+// or-ing together of all of the symbols that go into the set.
+//
+//------------------------------------------------------------------------
+void RBBISetBuilder::addValToSets(UVector *sets, uint32_t val) {
+ int32_t ix;
+
+ for (ix=0; ixsize(); ix++) {
+ RBBINode *usetNode = (RBBINode *)sets->elementAt(ix);
+ addValToSet(usetNode, val);
+ }
+}
+
+void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
+ RBBINode *leafNode = new RBBINode(RBBINode::leafChar);
+ leafNode->fVal = (unsigned short)val;
+ if (usetNode->fLeftChild == NULL) {
+ usetNode->fLeftChild = leafNode;
+ leafNode->fParent = usetNode;
+ } else {
+ // There are already input symbols present for this set.
+ // Set up an OR node, with the previous stuff as the left child
+ // and the new value as the right child.
+ RBBINode *orNode = new RBBINode(RBBINode::opOr);
+ orNode->fLeftChild = usetNode->fLeftChild;
+ orNode->fRightChild = leafNode;
+ orNode->fLeftChild->fParent = orNode;
+ orNode->fRightChild->fParent = orNode;
+ usetNode->fLeftChild = orNode;
+ orNode->fParent = usetNode;
+ }
+}
+
+
+//------------------------------------------------------------------------
+//
+// getNumCharCategories
+//
+//------------------------------------------------------------------------
+int32_t RBBISetBuilder::getNumCharCategories() const {
+ return fGroupCount + 3;
+}
+
+
+//------------------------------------------------------------------------
+//
+// sawBOF
+//
+//------------------------------------------------------------------------
+UBool RBBISetBuilder::sawBOF() const {
+ return fSawBOF;
+}
+
+
+//------------------------------------------------------------------------
+//
+// getFirstChar Given a runtime RBBI character category, find
+// the first UChar32 that is in the set of chars
+// in the category.
+//------------------------------------------------------------------------
+UChar32 RBBISetBuilder::getFirstChar(int32_t category) const {
+ RangeDescriptor *rlRange;
+ UChar32 retVal = (UChar32)-1;
+ for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
+ if (rlRange->fNum == category) {
+ retVal = rlRange->fStartChar;
+ break;
+ }
+ }
+ return retVal;
+}
+
+
+
+//------------------------------------------------------------------------
+//
+// printRanges A debugging function.
+// dump out all of the range definitions.
+//
+//------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBISetBuilder::printRanges() {
+ RangeDescriptor *rlRange;
+ int i;
+
+ RBBIDebugPrintf("\n\n Nonoverlapping Ranges ...\n");
+ for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
+ RBBIDebugPrintf("%2i %4x-%4x ", rlRange->fNum, rlRange->fStartChar, rlRange->fEndChar);
+
+ for (i=0; ifIncludesSets->size(); i++) {
+ RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
+ UnicodeString setName = UNICODE_STRING("anon", 4);
+ RBBINode *setRef = usetNode->fParent;
+ if (setRef != NULL) {
+ RBBINode *varRef = setRef->fParent;
+ if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ setName = varRef->fText;
+ }
+ }
+ RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" ");
+ }
+ RBBIDebugPrintf("\n");
+ }
+}
+#endif
+
+
+//------------------------------------------------------------------------
+//
+// printRangeGroups A debugging function.
+// dump out all of the range groups.
+//
+//------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBISetBuilder::printRangeGroups() {
+ RangeDescriptor *rlRange;
+ RangeDescriptor *tRange;
+ int i;
+ int lastPrintedGroupNum = 0;
+
+ RBBIDebugPrintf("\nRanges grouped by Unicode Set Membership...\n");
+ for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
+ int groupNum = rlRange->fNum & 0xbfff;
+ if (groupNum > lastPrintedGroupNum) {
+ lastPrintedGroupNum = groupNum;
+ RBBIDebugPrintf("%2i ", groupNum);
+
+ if (rlRange->fNum & 0x4000) { RBBIDebugPrintf(" ");}
+
+ for (i=0; ifIncludesSets->size(); i++) {
+ RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
+ UnicodeString setName = UNICODE_STRING("anon", 4);
+ RBBINode *setRef = usetNode->fParent;
+ if (setRef != NULL) {
+ RBBINode *varRef = setRef->fParent;
+ if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ setName = varRef->fText;
+ }
+ }
+ RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" ");
+ }
+
+ i = 0;
+ for (tRange = rlRange; tRange != 0; tRange = tRange->fNext) {
+ if (tRange->fNum == rlRange->fNum) {
+ if (i++ % 5 == 0) {
+ RBBIDebugPrintf("\n ");
+ }
+ RBBIDebugPrintf(" %05x-%05x", tRange->fStartChar, tRange->fEndChar);
+ }
+ }
+ RBBIDebugPrintf("\n");
+ }
+ }
+ RBBIDebugPrintf("\n");
+}
+#endif
+
+
+//------------------------------------------------------------------------
+//
+// printSets A debugging function.
+// dump out all of the set definitions.
+//
+//------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBISetBuilder::printSets() {
+ int i;
+
+ RBBIDebugPrintf("\n\nUnicode Sets List\n------------------\n");
+ for (i=0; ; i++) {
+ RBBINode *usetNode;
+ RBBINode *setRef;
+ RBBINode *varRef;
+ UnicodeString setName;
+
+ usetNode = (RBBINode *)fRB->fUSetNodes->elementAt(i);
+ if (usetNode == NULL) {
+ break;
+ }
+
+ RBBIDebugPrintf("%3d ", i);
+ setName = UNICODE_STRING("anonymous", 9);
+ setRef = usetNode->fParent;
+ if (setRef != NULL) {
+ varRef = setRef->fParent;
+ if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ setName = varRef->fText;
+ }
+ }
+ RBBI_DEBUG_printUnicodeString(setName);
+ RBBIDebugPrintf(" ");
+ RBBI_DEBUG_printUnicodeString(usetNode->fText);
+ RBBIDebugPrintf("\n");
+ if (usetNode->fLeftChild != NULL) {
+ usetNode->fLeftChild->printTree(TRUE);
+ }
+ }
+ RBBIDebugPrintf("\n");
+}
+#endif
+
+
+
+//-------------------------------------------------------------------------------------
+//
+// RangeDescriptor copy constructor
+//
+//-------------------------------------------------------------------------------------
+
+RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &status) {
+ int i;
+
+ this->fStartChar = other.fStartChar;
+ this->fEndChar = other.fEndChar;
+ this->fNum = other.fNum;
+ this->fNext = NULL;
+ UErrorCode oldstatus = status;
+ this->fIncludesSets = new UVector(status);
+ if (U_FAILURE(oldstatus)) {
+ status = oldstatus;
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+ /* test for NULL */
+ if (this->fIncludesSets == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ for (i=0; isize(); i++) {
+ this->fIncludesSets->addElement(other.fIncludesSets->elementAt(i), status);
+ }
+}
+
+
+//-------------------------------------------------------------------------------------
+//
+// RangeDesriptor default constructor
+//
+//-------------------------------------------------------------------------------------
+RangeDescriptor::RangeDescriptor(UErrorCode &status) {
+ this->fStartChar = 0;
+ this->fEndChar = 0;
+ this->fNum = 0;
+ this->fNext = NULL;
+ UErrorCode oldstatus = status;
+ this->fIncludesSets = new UVector(status);
+ if (U_FAILURE(oldstatus)) {
+ status = oldstatus;
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+ /* test for NULL */
+ if(this->fIncludesSets == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+}
+
+
+//-------------------------------------------------------------------------------------
+//
+// RangeDesriptor Destructor
+//
+//-------------------------------------------------------------------------------------
+RangeDescriptor::~RangeDescriptor() {
+ delete fIncludesSets;
+ fIncludesSets = NULL;
+}
+
+//-------------------------------------------------------------------------------------
+//
+// RangeDesriptor::split()
+//
+//-------------------------------------------------------------------------------------
+void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
+ U_ASSERT(where>fStartChar && where<=fEndChar);
+ RangeDescriptor *nr = new RangeDescriptor(*this, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ /* test for NULL */
+ if(nr == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ // RangeDescriptor copy constructor copies all fields.
+ // Only need to update those that are different after the split.
+ nr->fStartChar = where;
+ this->fEndChar = where-1;
+ nr->fNext = this->fNext;
+ this->fNext = nr;
+}
+
+
+//-------------------------------------------------------------------------------------
+//
+// RangeDescriptor::setDictionaryFlag
+//
+// Character Category Numbers that include characters from
+// the original Unicode Set named "dictionary" have bit 14
+// set to 1. The RBBI runtime engine uses this to trigger
+// use of the word dictionary.
+//
+// This function looks through the Unicode Sets that it
+// (the range) includes, and sets the bit in fNum when
+// "dictionary" is among them.
+//
+// TODO: a faster way would be to find the set node for
+// "dictionary" just once, rather than looking it
+// up by name every time.
+//
+//-------------------------------------------------------------------------------------
+void RangeDescriptor::setDictionaryFlag() {
+ int i;
+
+ for (i=0; ifIncludesSets->size(); i++) {
+ RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i);
+ UnicodeString setName;
+ RBBINode *setRef = usetNode->fParent;
+ if (setRef != NULL) {
+ RBBINode *varRef = setRef->fParent;
+ if (varRef != NULL && varRef->fType == RBBINode::varRef) {
+ setName = varRef->fText;
+ }
+ }
+ if (setName.compare(UNICODE_STRING("dictionary", 10)) == 0) { // TODO: no string literals.
+ this->fNum |= 0x4000;
+ break;
+ }
+ }
+}
+
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbisetb.h b/Build/source/libs/icu/icu-xetex/common/rbbisetb.h
new file mode 100644
index 00000000000..c8bc1df7786
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbisetb.h
@@ -0,0 +1,130 @@
+//
+// rbbisetb.h
+/*
+**********************************************************************
+* Copyright (c) 2001-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#ifndef RBBISETB_H
+#define RBBISETB_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "rbbirb.h"
+#include "uvector.h"
+
+struct UNewTrie;
+
+U_NAMESPACE_BEGIN
+
+//
+// RBBISetBuilder Derives the character categories used by the runtime RBBI engine
+// from the Unicode Sets appearing in the source RBBI rules, and
+// creates the TRIE table used to map from Unicode to the
+// character categories.
+//
+
+
+//
+// RangeDescriptor
+//
+// Each of the non-overlapping character ranges gets one of these descriptors.
+// All of them are strung together in a linked list, which is kept in order
+// (by character)
+//
+class RangeDescriptor : public UMemory {
+public:
+ UChar32 fStartChar; // Start of range, unicode 32 bit value.
+ UChar32 fEndChar; // End of range, unicode 32 bit value.
+ int32_t fNum; // runtime-mapped input value for this range.
+ UVector *fIncludesSets; // vector of the the original
+ // Unicode sets that include this range.
+ // (Contains ptrs to uset nodes)
+ RangeDescriptor *fNext; // Next RangeDescriptor in the linked list.
+
+ RangeDescriptor(UErrorCode &status);
+ RangeDescriptor(const RangeDescriptor &other, UErrorCode &status);
+ ~RangeDescriptor();
+ void split(UChar32 where, UErrorCode &status); // Spit this range in two at "where", with
+ // where appearing in the second (higher) part.
+ void setDictionaryFlag(); // Check whether this range appears as part of
+ // the Unicode set named "dictionary"
+
+private:
+ RangeDescriptor(const RangeDescriptor &other); // forbid copying of this class
+ RangeDescriptor &operator=(const RangeDescriptor &other); // forbid copying of this class
+};
+
+
+//
+// RBBISetBuilder Handles processing of Unicode Sets from RBBI rules.
+//
+// Starting with the rules parse tree from the scanner,
+//
+// - Enumerate the set of UnicodeSets that are referenced
+// by the RBBI rules.
+// - compute a derived set of non-overlapping UnicodeSets
+// that will correspond to columns in the state table for
+// the RBBI execution engine.
+// - construct the trie table that maps input characters
+// to set numbers in the non-overlapping set of sets.
+//
+
+
+class RBBISetBuilder : public UMemory {
+public:
+ RBBISetBuilder(RBBIRuleBuilder *rb);
+ ~RBBISetBuilder();
+
+ void build();
+ void addValToSets(UVector *sets, uint32_t val);
+ void addValToSet (RBBINode *usetNode, uint32_t val);
+ int32_t getNumCharCategories() const; // CharCategories are the same as input symbol set to the
+ // runtime state machine, which are the same as
+ // columns in the DFA state table
+ int32_t getTrieSize() /*const*/; // Size in bytes of the serialized Trie.
+ void serializeTrie(uint8_t *where); // write out the serialized Trie.
+ UChar32 getFirstChar(int32_t val) const;
+ UBool sawBOF() const; // Indicate whether any references to the {bof} pseudo
+ // character were encountered.
+#ifdef RBBI_DEBUG
+ void printSets();
+ void printRanges();
+ void printRangeGroups();
+#else
+ #define printSets()
+ #define printRanges()
+ #define printRangeGroups()
+#endif
+
+private:
+ void numberSets();
+
+ RBBIRuleBuilder *fRB; // The RBBI Rule Compiler that owns us.
+ UErrorCode *fStatus;
+
+ RangeDescriptor *fRangeList; // Head of the linked list of RangeDescriptors
+
+ UNewTrie *fTrie; // The mapping TRIE that is the end result of processing
+ uint32_t fTrieSize; // the Unicode Sets.
+
+ // Groups correspond to character categories -
+ // groups of ranges that are in the same original UnicodeSets.
+ // fGroupCount is the index of the last used group.
+ // fGroupCount+1 is also the number of columns in the RBBI state table being compiled.
+ // State table column 0 is not used. Column 1 is for end-of-input.
+ // column 2 is for group 0. Funny counting.
+ int32_t fGroupCount;
+
+ UBool fSawBOF;
+
+ RBBISetBuilder(const RBBISetBuilder &other); // forbid copying of this class
+ RBBISetBuilder &operator=(const RBBISetBuilder &other); // forbid copying of this class
+};
+
+
+
+U_NAMESPACE_END
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbistbl.cpp b/Build/source/libs/icu/icu-xetex/common/rbbistbl.cpp
new file mode 100644
index 00000000000..cbcd3815509
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbistbl.cpp
@@ -0,0 +1,269 @@
+//
+// file: rbbistbl.cpp Implementation of the ICU RBBISymbolTable class
+//
+/*
+***************************************************************************
+* Copyright (C) 2002-2006 International Business Machines Corporation *
+* and others. All rights reserved. *
+***************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/parsepos.h"
+
+#include "umutex.h"
+
+#include "rbbirb.h"
+#include "rbbinode.h"
+
+
+//
+// RBBISymbolTableEntry_deleter Used by the UHashTable to delete the contents
+// when the hash table is deleted.
+//
+U_CDECL_BEGIN
+static void U_CALLCONV RBBISymbolTableEntry_deleter(void *p) {
+ U_NAMESPACE_QUALIFIER RBBISymbolTableEntry *px = (U_NAMESPACE_QUALIFIER RBBISymbolTableEntry *)p;
+ delete px;
+}
+U_CDECL_END
+
+
+
+U_NAMESPACE_BEGIN
+
+RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status)
+ :fRules(rules), fRuleScanner(rs), ffffString(UChar(0xffff))
+{
+ fHashTable = NULL;
+ fCachedSetLookup = NULL;
+
+ fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status);
+ // uhash_open checks status
+ if (U_FAILURE(status)) {
+ return;
+ }
+ uhash_setValueDeleter(fHashTable, RBBISymbolTableEntry_deleter);
+}
+
+
+
+RBBISymbolTable::~RBBISymbolTable()
+{
+ uhash_close(fHashTable);
+}
+
+
+//
+// RBBISymbolTable::lookup This function from the abstract symbol table inteface
+// looks up a variable name and returns a UnicodeString
+// containing the substitution text.
+//
+// The variable name does NOT include the leading $.
+//
+const UnicodeString *RBBISymbolTable::lookup(const UnicodeString& s) const
+{
+ RBBISymbolTableEntry *el;
+ RBBINode *varRefNode;
+ RBBINode *exprNode;
+ RBBINode *usetNode;
+ const UnicodeString *retString;
+ RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
+
+ el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &s);
+ if (el == NULL) {
+ return NULL;
+ }
+
+ varRefNode = el->val;
+ exprNode = varRefNode->fLeftChild; // Root node of expression for variable
+ if (exprNode->fType == RBBINode::setRef) {
+ // The $variable refers to a single UnicodeSet
+ // return the ffffString, which will subsequently be interpreted as a
+ // stand-in character for the set by RBBISymbolTable::lookupMatcher()
+ usetNode = exprNode->fLeftChild;
+ This->fCachedSetLookup = usetNode->fInputSet;
+ retString = &ffffString;
+ }
+ else
+ {
+ // The variable refers to something other than just a set.
+ // return the original source string for the expression
+ retString = &exprNode->fText;
+ This->fCachedSetLookup = NULL;
+ }
+ return retString;
+}
+
+
+
+//
+// RBBISymbolTable::lookupMatcher This function from the abstract symbol table
+// interface maps a single stand-in character to a
+// pointer to a Unicode Set. The Unicode Set code uses this
+// mechanism to get all references to the same $variable
+// name to refer to a single common Unicode Set instance.
+//
+// This implementation cheats a little, and does not maintain a map of stand-in chars
+// to sets. Instead, it takes advantage of the fact that the UnicodeSet
+// constructor will always call this function right after calling lookup(),
+// and we just need to remember what set to return between these two calls.
+const UnicodeFunctor *RBBISymbolTable::lookupMatcher(UChar32 ch) const
+{
+ UnicodeSet *retVal = NULL;
+ RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
+ if (ch == 0xffff) {
+ retVal = fCachedSetLookup;
+ This->fCachedSetLookup = 0;
+ }
+ return retVal;
+}
+
+//
+// RBBISymbolTable::parseReference This function from the abstract symbol table interface
+// looks for a $variable name in the source text.
+// It does not look it up, only scans for it.
+// It is used by the UnicodeSet parser.
+//
+// This implementation is lifted pretty much verbatim
+// from the rules based transliterator implementation.
+// I didn't see an obvious way of sharing it.
+//
+UnicodeString RBBISymbolTable::parseReference(const UnicodeString& text,
+ ParsePosition& pos, int32_t limit) const
+{
+ int32_t start = pos.getIndex();
+ int32_t i = start;
+ UnicodeString result;
+ while (i < limit) {
+ UChar c = text.charAt(i);
+ if ((i==start && !u_isIDStart(c)) || !u_isIDPart(c)) {
+ break;
+ }
+ ++i;
+ }
+ if (i == start) { // No valid name chars
+ return result; // Indicate failure with empty string
+ }
+ pos.setIndex(i);
+ text.extractBetween(start, i, result);
+ return result;
+}
+
+
+
+//
+// RBBISymbolTable::lookupNode Given a key (a variable name), return the
+// corresponding RBBI Node. If there is no entry
+// in the table for this name, return NULL.
+//
+RBBINode *RBBISymbolTable::lookupNode(const UnicodeString &key) const{
+
+ RBBINode *retNode = NULL;
+ RBBISymbolTableEntry *el;
+
+ el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
+ if (el != NULL) {
+ retNode = el->val;
+ }
+ return retNode;
+}
+
+
+//
+// RBBISymbolTable::addEntry Add a new entry to the symbol table.
+// Indicate an error if the name already exists -
+// this will only occur in the case of duplicate
+// variable assignments.
+//
+void RBBISymbolTable::addEntry (const UnicodeString &key, RBBINode *val, UErrorCode &err) {
+ RBBISymbolTableEntry *e;
+ /* test for buffer overflows */
+ if (U_FAILURE(err)) {
+ return;
+ }
+ e = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
+ if (e != NULL) {
+ err = U_BRK_VARIABLE_REDFINITION;
+ return;
+ }
+
+ e = new RBBISymbolTableEntry;
+ if (e == NULL) {
+ err = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ e->key = key;
+ e->val = val;
+ uhash_put( fHashTable, &e->key, e, &err);
+}
+
+
+RBBISymbolTableEntry::RBBISymbolTableEntry() : UMemory(), key(), val(NULL) {}
+
+RBBISymbolTableEntry::~RBBISymbolTableEntry() {
+ // The "val" of a symbol table entry is a variable reference node.
+ // The l. child of the val is the rhs expression from the assignment.
+ // Unlike other node types, children of variable reference nodes are not
+ // automatically recursively deleted. We do it manually here.
+ delete val->fLeftChild;
+ val->fLeftChild = NULL;
+
+ delete val;
+
+ // Note: the key UnicodeString is destructed by virtue of being in the object by value.
+}
+
+
+//
+// RBBISymbolTable::print Debugging function, dump out the symbol table contents.
+//
+#ifdef RBBI_DEBUG
+void RBBISymbolTable::rbbiSymtablePrint() const {
+ RBBIDebugPrintf("Variable Definitions\n"
+ "Name Node Val String Val\n"
+ "----------------------------------------------------------------------\n");
+
+ int32_t pos = -1;
+ const UHashElement *e = NULL;
+ for (;;) {
+ e = uhash_nextElement(fHashTable, &pos);
+ if (e == NULL ) {
+ break;
+ }
+ RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
+
+ RBBI_DEBUG_printUnicodeString(s->key, 15);
+ RBBIDebugPrintf(" %8p ", (void *)s->val);
+ RBBI_DEBUG_printUnicodeString(s->val->fLeftChild->fText);
+ RBBIDebugPrintf("\n");
+ }
+
+ RBBIDebugPrintf("\nParsed Variable Definitions\n");
+ pos = -1;
+ for (;;) {
+ e = uhash_nextElement(fHashTable, &pos);
+ if (e == NULL ) {
+ break;
+ }
+ RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
+ RBBI_DEBUG_printUnicodeString(s->key);
+ s->val->fLeftChild->printTree(TRUE);
+ RBBIDebugPrintf("\n");
+ }
+}
+#endif
+
+
+
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbitblb.cpp b/Build/source/libs/icu/icu-xetex/common/rbbitblb.cpp
new file mode 100644
index 00000000000..78fd1c51d9c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbitblb.cpp
@@ -0,0 +1,1232 @@
+/*
+**********************************************************************
+* Copyright (c) 2002-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+//
+// rbbitblb.cpp
+//
+
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/unistr.h"
+#include "rbbitblb.h"
+#include "rbbirb.h"
+#include "rbbisetb.h"
+#include "rbbidata.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+RBBITableBuilder::RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode) :
+ fTree(*rootNode) {
+ fRB = rb;
+ fStatus = fRB->fStatus;
+ UErrorCode status = U_ZERO_ERROR;
+ fDStates = new UVector(status);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ if (U_FAILURE(status)) {
+ *fStatus = status;
+ return;
+ }
+ if (fDStates == NULL) {
+ *fStatus = U_MEMORY_ALLOCATION_ERROR;;
+ }
+}
+
+
+
+RBBITableBuilder::~RBBITableBuilder() {
+ int i;
+ for (i=0; isize(); i++) {
+ delete (RBBIStateDescriptor *)fDStates->elementAt(i);
+ }
+ delete fDStates;
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// RBBITableBuilder::build - This is the main function for building the DFA state transtion
+// table from the RBBI rules parse tree.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::build() {
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // If there were no rules, just return. This situation can easily arise
+ // for the reverse rules.
+ if (fTree==NULL) {
+ return;
+ }
+
+ //
+ // Walk through the tree, replacing any references to $variables with a copy of the
+ // parse tree for the substition expression.
+ //
+ fTree = fTree->flattenVariables();
+#ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ftree")) {
+ RBBIDebugPuts("Parse tree after flattening variable references.");
+ fTree->printTree(TRUE);
+ }
+#endif
+
+ //
+ // If the rules contained any references to {bof}
+ // add a {bof} to the
+ // tree. Means that all matches must start out with the
+ // {bof} fake character.
+ //
+ if (fRB->fSetBuilder->sawBOF()) {
+ RBBINode *bofTop = new RBBINode(RBBINode::opCat);
+ RBBINode *bofLeaf = new RBBINode(RBBINode::leafChar);
+ bofTop->fLeftChild = bofLeaf;
+ bofTop->fRightChild = fTree;
+ bofLeaf->fParent = bofTop;
+ bofLeaf->fVal = 2; // Reserved value for {bof}.
+ fTree = bofTop;
+ }
+
+ //
+ // Add a unique right-end marker to the expression.
+ // Appears as a cat-node, left child being the original tree,
+ // right child being the end marker.
+ //
+ RBBINode *cn = new RBBINode(RBBINode::opCat);
+ cn->fLeftChild = fTree;
+ fTree->fParent = cn;
+ cn->fRightChild = new RBBINode(RBBINode::endMark);
+ cn->fRightChild->fParent = cn;
+ fTree = cn;
+
+ //
+ // Replace all references to UnicodeSets with the tree for the equivalent
+ // expression.
+ //
+ fTree->flattenSets();
+#ifdef RBBI_DEBUG
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "stree")) {
+ RBBIDebugPuts("Parse tree after flattening Unicode Set references.");
+ fTree->printTree(TRUE);
+ }
+#endif
+
+
+ //
+ // calculate the functions nullable, firstpos, lastpos and followpos on
+ // nodes in the parse tree.
+ // See the alogrithm description in Aho.
+ // Understanding how this works by looking at the code alone will be
+ // nearly impossible.
+ //
+ calcNullable(fTree);
+ calcFirstPos(fTree);
+ calcLastPos(fTree);
+ calcFollowPos(fTree);
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "pos")) {
+ RBBIDebugPuts("\n");
+ printPosSets(fTree);
+ }
+
+ //
+ // For "chained" rules, modify the followPos sets
+ //
+ if (fRB->fChainRules) {
+ calcChainedFollowPos(fTree);
+ }
+
+ //
+ // BOF (start of input) test fixup.
+ //
+ if (fRB->fSetBuilder->sawBOF()) {
+ bofFixup();
+ }
+
+ //
+ // Build the DFA state transition tables.
+ //
+ buildStateTable();
+ flagAcceptingStates();
+ flagLookAheadStates();
+ flagTaggedStates();
+
+ //
+ // Update the global table of rule status {tag} values
+ // The rule builder has a global vector of status values that are common
+ // for all tables. Merge the ones from this table into the global set.
+ //
+ mergeRuleStatusVals();
+
+ if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "states")) {printStates();};
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// calcNullable. Impossible to explain succinctly. See Aho, section 3.9
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::calcNullable(RBBINode *n) {
+ if (n == NULL) {
+ return;
+ }
+ if (n->fType == RBBINode::setRef ||
+ n->fType == RBBINode::endMark ) {
+ // These are non-empty leaf node types.
+ n->fNullable = FALSE;
+ return;
+ }
+
+ if (n->fType == RBBINode::lookAhead || n->fType == RBBINode::tag) {
+ // Lookahead marker node. It's a leaf, so no recursion on children.
+ // It's nullable because it does not match any literal text from the input stream.
+ n->fNullable = TRUE;
+ return;
+ }
+
+
+ // The node is not a leaf.
+ // Calculate nullable on its children.
+ calcNullable(n->fLeftChild);
+ calcNullable(n->fRightChild);
+
+ // Apply functions from table 3.40 in Aho
+ if (n->fType == RBBINode::opOr) {
+ n->fNullable = n->fLeftChild->fNullable || n->fRightChild->fNullable;
+ }
+ else if (n->fType == RBBINode::opCat) {
+ n->fNullable = n->fLeftChild->fNullable && n->fRightChild->fNullable;
+ }
+ else if (n->fType == RBBINode::opStar || n->fType == RBBINode::opQuestion) {
+ n->fNullable = TRUE;
+ }
+ else {
+ n->fNullable = FALSE;
+ }
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+//
+// calcFirstPos. Impossible to explain succinctly. See Aho, section 3.9
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::calcFirstPos(RBBINode *n) {
+ if (n == NULL) {
+ return;
+ }
+ if (n->fType == RBBINode::leafChar ||
+ n->fType == RBBINode::endMark ||
+ n->fType == RBBINode::lookAhead ||
+ n->fType == RBBINode::tag) {
+ // These are non-empty leaf node types.
+ // Note: In order to maintain the sort invariant on the set,
+ // this function should only be called on a node whose set is
+ // empty to start with.
+ n->fFirstPosSet->addElement(n, *fStatus);
+ return;
+ }
+
+ // The node is not a leaf.
+ // Calculate firstPos on its children.
+ calcFirstPos(n->fLeftChild);
+ calcFirstPos(n->fRightChild);
+
+ // Apply functions from table 3.40 in Aho
+ if (n->fType == RBBINode::opOr) {
+ setAdd(n->fFirstPosSet, n->fLeftChild->fFirstPosSet);
+ setAdd(n->fFirstPosSet, n->fRightChild->fFirstPosSet);
+ }
+ else if (n->fType == RBBINode::opCat) {
+ setAdd(n->fFirstPosSet, n->fLeftChild->fFirstPosSet);
+ if (n->fLeftChild->fNullable) {
+ setAdd(n->fFirstPosSet, n->fRightChild->fFirstPosSet);
+ }
+ }
+ else if (n->fType == RBBINode::opStar ||
+ n->fType == RBBINode::opQuestion ||
+ n->fType == RBBINode::opPlus) {
+ setAdd(n->fFirstPosSet, n->fLeftChild->fFirstPosSet);
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// calcLastPos. Impossible to explain succinctly. See Aho, section 3.9
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::calcLastPos(RBBINode *n) {
+ if (n == NULL) {
+ return;
+ }
+ if (n->fType == RBBINode::leafChar ||
+ n->fType == RBBINode::endMark ||
+ n->fType == RBBINode::lookAhead ||
+ n->fType == RBBINode::tag) {
+ // These are non-empty leaf node types.
+ // Note: In order to maintain the sort invariant on the set,
+ // this function should only be called on a node whose set is
+ // empty to start with.
+ n->fLastPosSet->addElement(n, *fStatus);
+ return;
+ }
+
+ // The node is not a leaf.
+ // Calculate lastPos on its children.
+ calcLastPos(n->fLeftChild);
+ calcLastPos(n->fRightChild);
+
+ // Apply functions from table 3.40 in Aho
+ if (n->fType == RBBINode::opOr) {
+ setAdd(n->fLastPosSet, n->fLeftChild->fLastPosSet);
+ setAdd(n->fLastPosSet, n->fRightChild->fLastPosSet);
+ }
+ else if (n->fType == RBBINode::opCat) {
+ setAdd(n->fLastPosSet, n->fRightChild->fLastPosSet);
+ if (n->fRightChild->fNullable) {
+ setAdd(n->fLastPosSet, n->fLeftChild->fLastPosSet);
+ }
+ }
+ else if (n->fType == RBBINode::opStar ||
+ n->fType == RBBINode::opQuestion ||
+ n->fType == RBBINode::opPlus) {
+ setAdd(n->fLastPosSet, n->fLeftChild->fLastPosSet);
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// calcFollowPos. Impossible to explain succinctly. See Aho, section 3.9
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::calcFollowPos(RBBINode *n) {
+ if (n == NULL ||
+ n->fType == RBBINode::leafChar ||
+ n->fType == RBBINode::endMark) {
+ return;
+ }
+
+ calcFollowPos(n->fLeftChild);
+ calcFollowPos(n->fRightChild);
+
+ // Aho rule #1
+ if (n->fType == RBBINode::opCat) {
+ RBBINode *i; // is 'i' in Aho's description
+ uint32_t ix;
+
+ UVector *LastPosOfLeftChild = n->fLeftChild->fLastPosSet;
+
+ for (ix=0; ix<(uint32_t)LastPosOfLeftChild->size(); ix++) {
+ i = (RBBINode *)LastPosOfLeftChild->elementAt(ix);
+ setAdd(i->fFollowPos, n->fRightChild->fFirstPosSet);
+ }
+ }
+
+ // Aho rule #2
+ if (n->fType == RBBINode::opStar ||
+ n->fType == RBBINode::opPlus) {
+ RBBINode *i; // again, n and i are the names from Aho's description.
+ uint32_t ix;
+
+ for (ix=0; ix<(uint32_t)n->fLastPosSet->size(); ix++) {
+ i = (RBBINode *)n->fLastPosSet->elementAt(ix);
+ setAdd(i->fFollowPos, n->fFirstPosSet);
+ }
+ }
+
+
+
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// calcChainedFollowPos. Modify the previously calculated followPos sets
+// to implement rule chaining. NOT described by Aho
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::calcChainedFollowPos(RBBINode *tree) {
+
+ UVector endMarkerNodes(*fStatus);
+ UVector leafNodes(*fStatus);
+ int32_t i;
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // get a list of all endmarker nodes.
+ tree->findNodes(&endMarkerNodes, RBBINode::endMark, *fStatus);
+
+ // get a list all leaf nodes
+ tree->findNodes(&leafNodes, RBBINode::leafChar, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // Get all nodes that can be the start a match, which is FirstPosition()
+ // of the portion of the tree corresponding to user-written rules.
+ // See the tree description in bofFixup().
+ RBBINode *userRuleRoot = tree;
+ if (fRB->fSetBuilder->sawBOF()) {
+ userRuleRoot = tree->fLeftChild->fRightChild;
+ }
+ U_ASSERT(userRuleRoot != NULL);
+ UVector *matchStartNodes = userRuleRoot->fFirstPosSet;
+
+
+ // Iteratate over all leaf nodes,
+ //
+ int32_t endNodeIx;
+ int32_t startNodeIx;
+
+ for (endNodeIx=0; endNodeIxfFollowPos->contains(endMarkerNodes.elementAt(i))) {
+ endNode = tNode;
+ break;
+ }
+ }
+ if (endNode == NULL) {
+ // node wasn't an end node. Try again with the next.
+ continue;
+ }
+
+ // We've got a node that can end a match.
+
+ // Line Break Specific hack: If this node's val correspond to the $CM char class,
+ // don't chain from it.
+ // TODO: Add rule syntax for this behavior, get specifics out of here and
+ // into the rule file.
+ if (fRB->fLBCMNoChain) {
+ UChar32 c = this->fRB->fSetBuilder->getFirstChar(endNode->fVal);
+ if (c != -1) {
+ // c == -1 occurs with sets containing only the {eof} marker string.
+ ULineBreak cLBProp = (ULineBreak)u_getIntPropertyValue(c, UCHAR_LINE_BREAK);
+ if (cLBProp == U_LB_COMBINING_MARK) {
+ continue;
+ }
+ }
+ }
+
+
+ // Now iterate over the nodes that can start a match, looking for ones
+ // with the same char class as our ending node.
+ RBBINode *startNode;
+ for (startNodeIx = 0; startNodeIxsize(); startNodeIx++) {
+ startNode = (RBBINode *)matchStartNodes->elementAt(startNodeIx);
+ if (startNode->fType != RBBINode::leafChar) {
+ continue;
+ }
+
+ if (endNode->fVal == startNode->fVal) {
+ // The end val (character class) of one possible match is the
+ // same as the start of another.
+
+ // Add all nodes from the followPos of the start node to the
+ // followPos set of the end node, which will have the effect of
+ // letting matches transition from a match state at endNode
+ // to the second char of a match starting with startNode.
+ setAdd(endNode->fFollowPos, startNode->fFollowPos);
+ }
+ }
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// bofFixup. Fixup for state tables that include {bof} beginning of input testing.
+// Do an swizzle similar to chaining, modifying the followPos set of
+// the bofNode to include the followPos nodes from other {bot} nodes
+// scattered through the tree.
+//
+// This function has much in common with calcChainedFollowPos().
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::bofFixup() {
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // The parse tree looks like this ...
+ // fTree root --->
+ // / \ .
+ // <#end node>
+ // / \ .
+ // rest
+ // of tree
+ //
+ // We will be adding things to the followPos set of the
+ //
+ RBBINode *bofNode = fTree->fLeftChild->fLeftChild;
+ U_ASSERT(bofNode->fType == RBBINode::leafChar);
+ U_ASSERT(bofNode->fVal == 2);
+
+ // Get all nodes that can be the start a match of the user-written rules
+ // (excluding the fake bofNode)
+ // We want the nodes that can start a match in the
+ // part labeled "rest of tree"
+ //
+ UVector *matchStartNodes = fTree->fLeftChild->fRightChild->fFirstPosSet;
+
+ RBBINode *startNode;
+ int startNodeIx;
+ for (startNodeIx = 0; startNodeIxsize(); startNodeIx++) {
+ startNode = (RBBINode *)matchStartNodes->elementAt(startNodeIx);
+ if (startNode->fType != RBBINode::leafChar) {
+ continue;
+ }
+
+ if (startNode->fVal == bofNode->fVal) {
+ // We found a leaf node corresponding to a {bof} that was
+ // explicitly written into a rule.
+ // Add everything from the followPos set of this node to the
+ // followPos set of the fake bofNode at the start of the tree.
+ //
+ setAdd(bofNode->fFollowPos, startNode->fFollowPos);
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+//
+// buildStateTable() Determine the set of runtime DFA states and the
+// transition tables for these states, by the algorithm
+// of fig. 3.44 in Aho.
+//
+// Most of the comments are quotes of Aho's psuedo-code.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::buildStateTable() {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ //
+ // Add a dummy state 0 - the stop state. Not from Aho.
+ int lastInputSymbol = fRB->fSetBuilder->getNumCharCategories() - 1;
+ RBBIStateDescriptor *failState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
+ failState->fPositions = new UVector(*fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ fDStates->addElement(failState, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // initially, the only unmarked state in Dstates is firstpos(root),
+ // where toot is the root of the syntax tree for (r)#;
+ RBBIStateDescriptor *initialState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ initialState->fPositions = new UVector(*fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ setAdd(initialState->fPositions, fTree->fFirstPosSet);
+ fDStates->addElement(initialState, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // while there is an unmarked state T in Dstates do begin
+ for (;;) {
+ RBBIStateDescriptor *T = NULL;
+ int32_t tx;
+ for (tx=1; txsize(); tx++) {
+ RBBIStateDescriptor *temp;
+ temp = (RBBIStateDescriptor *)fDStates->elementAt(tx);
+ if (temp->fMarked == FALSE) {
+ T = temp;
+ break;
+ }
+ }
+ if (T == NULL) {
+ break;
+ }
+
+ // mark T;
+ T->fMarked = TRUE;
+
+ // for each input symbol a do begin
+ int32_t a;
+ for (a = 1; a<=lastInputSymbol; a++) {
+ // let U be the set of positions that are in followpos(p)
+ // for some position p in T
+ // such that the symbol at position p is a;
+ UVector *U = NULL;
+ RBBINode *p;
+ int32_t px;
+ for (px=0; pxfPositions->size(); px++) {
+ p = (RBBINode *)T->fPositions->elementAt(px);
+ if ((p->fType == RBBINode::leafChar) && (p->fVal == a)) {
+ if (U == NULL) {
+ U = new UVector(*fStatus);
+ }
+ setAdd(U, p->fFollowPos);
+ }
+ }
+
+ // if U is not empty and not in DStates then
+ int32_t ux = 0;
+ UBool UinDstates = FALSE;
+ if (U != NULL) {
+ U_ASSERT(U->size() > 0);
+ int ix;
+ for (ix=0; ixsize(); ix++) {
+ RBBIStateDescriptor *temp2;
+ temp2 = (RBBIStateDescriptor *)fDStates->elementAt(ix);
+ if (setEquals(U, temp2->fPositions)) {
+ delete U;
+ U = temp2->fPositions;
+ ux = ix;
+ UinDstates = TRUE;
+ break;
+ }
+ }
+
+ // Add U as an unmarked state to Dstates
+ if (!UinDstates)
+ {
+ RBBIStateDescriptor *newState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ newState->fPositions = U;
+ fDStates->addElement(newState, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ ux = fDStates->size()-1;
+ }
+
+ // Dtran[T, a] := U;
+ T->fDtran->setElementAt(ux, a);
+ }
+ }
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// flagAcceptingStates Identify accepting states.
+// First get a list of all of the end marker nodes.
+// Then, for each state s,
+// if s contains one of the end marker nodes in its list of tree positions then
+// s is an accepting state.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::flagAcceptingStates() {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ UVector endMarkerNodes(*fStatus);
+ RBBINode *endMarker;
+ int32_t i;
+ int32_t n;
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ fTree->findNodes(&endMarkerNodes, RBBINode::endMark, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ for (i=0; isize(); n++) {
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
+ if (sd->fPositions->indexOf(endMarker) >= 0) {
+ // Any non-zero value for fAccepting means this is an accepting node.
+ // The value is what will be returned to the user as the break status.
+ // If no other value was specified, force it to -1.
+
+ if (sd->fAccepting==0) {
+ // State hasn't been marked as accepting yet. Do it now.
+ sd->fAccepting = endMarker->fVal;
+ if (sd->fAccepting == 0) {
+ sd->fAccepting = -1;
+ }
+ }
+ if (sd->fAccepting==-1 && endMarker->fVal != 0) {
+ // Both lookahead and non-lookahead accepting for this state.
+ // Favor the look-ahead. Expedient for line break.
+ // TODO: need a more elegant resolution for conflicting rules.
+ sd->fAccepting = endMarker->fVal;
+ }
+ // implicit else:
+ // if sd->fAccepting already had a value other than 0 or -1, leave it be.
+
+ // If the end marker node is from a look-ahead rule, set
+ // the fLookAhead field or this state also.
+ if (endMarker->fLookAheadEnd) {
+ // TODO: don't change value if already set?
+ // TODO: allow for more than one active look-ahead rule in engine.
+ // Make value here an index to a side array in engine?
+ sd->fLookAhead = sd->fAccepting;
+ }
+ }
+ }
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// flagLookAheadStates Very similar to flagAcceptingStates, above.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::flagLookAheadStates() {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ UVector lookAheadNodes(*fStatus);
+ RBBINode *lookAheadNode;
+ int32_t i;
+ int32_t n;
+
+ fTree->findNodes(&lookAheadNodes, RBBINode::lookAhead, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ for (i=0; isize(); n++) {
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
+ if (sd->fPositions->indexOf(lookAheadNode) >= 0) {
+ sd->fLookAhead = lookAheadNode->fVal;
+ }
+ }
+ }
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+//
+// flagTaggedStates
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::flagTaggedStates() {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ UVector tagNodes(*fStatus);
+ RBBINode *tagNode;
+ int32_t i;
+ int32_t n;
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ fTree->findNodes(&tagNodes, RBBINode::tag, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ for (i=0; isize(); n++) { // For each state s (row in the state table)
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
+ if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t
+ sortedAdd(&sd->fTagVals, tagNode->fVal);
+ }
+ }
+ }
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+//
+// mergeRuleStatusVals
+//
+// Update the global table of rule status {tag} values
+// The rule builder has a global vector of status values that are common
+// for all tables. Merge the ones from this table into the global set.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::mergeRuleStatusVals() {
+ //
+ // The basic outline of what happens here is this...
+ //
+ // for each state in this state table
+ // if the status tag list for this state is in the global statuses list
+ // record where and
+ // continue with the next state
+ // else
+ // add the tag list for this state to the global list.
+ //
+ int i;
+ int n;
+
+ // Pre-set a single tag of {0} into the table.
+ // We will need this as a default, for rule sets with no explicit tagging.
+ if (fRB->fRuleStatusVals->size() == 0) {
+ fRB->fRuleStatusVals->addElement(1, *fStatus); // Num of statuses in group
+ fRB->fRuleStatusVals->addElement((int32_t)0, *fStatus); // and our single status of zero
+ }
+
+ // For each state
+ for (n=0; nsize(); n++) {
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
+ UVector *thisStatesTagValues = sd->fTagVals;
+ if (thisStatesTagValues == NULL) {
+ // No tag values are explicitly associated with this state.
+ // Set the default tag value.
+ sd->fTagsIdx = 0;
+ continue;
+ }
+
+ // There are tag(s) associated with this state.
+ // fTagsIdx will be the index into the global tag list for this state's tag values.
+ // Initial value of -1 flags that we haven't got it set yet.
+ sd->fTagsIdx = -1;
+ int32_t thisTagGroupStart = 0; // indexes into the global rule status vals list
+ int32_t nextTagGroupStart = 0;
+
+ // Loop runs once per group of tags in the global list
+ while (nextTagGroupStart < fRB->fRuleStatusVals->size()) {
+ thisTagGroupStart = nextTagGroupStart;
+ nextTagGroupStart += fRB->fRuleStatusVals->elementAti(thisTagGroupStart) + 1;
+ if (thisStatesTagValues->size() != fRB->fRuleStatusVals->elementAti(thisTagGroupStart)) {
+ // The number of tags for this state is different from
+ // the number of tags in this group from the global list.
+ // Continue with the next group from the global list.
+ continue;
+ }
+ // The lengths match, go ahead and compare the actual tag values
+ // between this state and the group from the global list.
+ for (i=0; isize(); i++) {
+ if (thisStatesTagValues->elementAti(i) !=
+ fRB->fRuleStatusVals->elementAti(thisTagGroupStart + 1 + i) ) {
+ // Mismatch.
+ break;
+ }
+ }
+
+ if (i == thisStatesTagValues->size()) {
+ // We found a set of tag values in the global list that match
+ // those for this state. Use them.
+ sd->fTagsIdx = thisTagGroupStart;
+ break;
+ }
+ }
+
+ if (sd->fTagsIdx == -1) {
+ // No suitable entry in the global tag list already. Add one
+ sd->fTagsIdx = fRB->fRuleStatusVals->size();
+ fRB->fRuleStatusVals->addElement(thisStatesTagValues->size(), *fStatus);
+ for (i=0; isize(); i++) {
+ fRB->fRuleStatusVals->addElement(thisStatesTagValues->elementAti(i), *fStatus);
+ }
+ }
+ }
+}
+
+
+
+
+
+
+
+//-----------------------------------------------------------------------------
+//
+// sortedAdd Add a value to a vector of sorted values (ints).
+// Do not replicate entries; if the value is already there, do not
+// add a second one.
+// Lazily create the vector if it does not already exist.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::sortedAdd(UVector **vector, int32_t val) {
+ int32_t i;
+
+ if (*vector == NULL) {
+ *vector = new UVector(*fStatus);
+ }
+ if (*vector == NULL || U_FAILURE(*fStatus)) {
+ return;
+ }
+ UVector *vec = *vector;
+ int32_t vSize = vec->size();
+ for (i=0; ielementAti(i);
+ if (valAtI == val) {
+ // The value is already in the vector. Don't add it again.
+ return;
+ }
+ if (valAtI > val) {
+ break;
+ }
+ }
+ vec->insertElementAt(val, i, *fStatus);
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// setAdd Set operation on UVector
+// dest = dest union source
+// Elements may only appear once and must be sorted.
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::setAdd(UVector *dest, UVector *source) {
+ int32_t destOriginalSize = dest->size();
+ int32_t sourceSize = source->size();
+ int32_t di = 0;
+ void *(destS[16]), *(sourceS[16]); // Handle small cases without malloc
+ void **destH = 0, **sourceH = 0;
+ void **destBuff, **sourceBuff;
+ void **destLim, **sourceLim;
+
+ if (destOriginalSize > (int32_t)(sizeof(destS)/sizeof(destS[0]))) {
+ destH = (void **)uprv_malloc(sizeof(void *) * destOriginalSize);
+ destBuff = destH;
+ }
+ else {
+ destBuff = destS;
+ }
+ if (destBuff == 0) {
+ return;
+ }
+ destLim = destBuff + destOriginalSize;
+
+ if (sourceSize > (int32_t)(sizeof(sourceS)/sizeof(sourceS[0]))) {
+ sourceH = (void **)uprv_malloc(sizeof(void *) * sourceSize);
+ sourceBuff = sourceH;
+ }
+ else {
+ sourceBuff = sourceS;
+ }
+ if (sourceBuff == 0) {
+ if (destH) {
+ uprv_free(destH);
+ }
+ return;
+ }
+ sourceLim = sourceBuff + sourceSize;
+
+ // Avoid multiple "get element" calls by getting the contents into arrays
+ (void) dest->toArray(destBuff);
+ (void) source->toArray(sourceBuff);
+
+ dest->setSize(sourceSize+destOriginalSize);
+
+ while (sourceBuff < sourceLim && destBuff < destLim) {
+ if (*destBuff == *sourceBuff) {
+ dest->setElementAt(*sourceBuff++, di++);
+ destBuff++;
+ }
+ // This check is required for machines with segmented memory, like i5/OS.
+ // Direct pointer comparison is not recommended.
+ else if (uprv_memcmp(destBuff, sourceBuff, sizeof(void *)) < 0) {
+ dest->setElementAt(*destBuff++, di++);
+ }
+ else { /* *sourceBuff < *destBuff */
+ dest->setElementAt(*sourceBuff++, di++);
+ }
+ }
+
+ // At most one of these two cleanup loops will execute
+ while (destBuff < destLim) {
+ dest->setElementAt(*destBuff++, di++);
+ }
+ while (sourceBuff < sourceLim) {
+ dest->setElementAt(*sourceBuff++, di++);
+ }
+
+ dest->setSize(di);
+ if (destH) {
+ uprv_free(destH);
+ }
+ if (sourceH) {
+ uprv_free(sourceH);
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// setEqual Set operation on UVector.
+// Compare for equality.
+// Elements must be sorted.
+//
+//-----------------------------------------------------------------------------
+UBool RBBITableBuilder::setEquals(UVector *a, UVector *b) {
+ return a->equals(*b);
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// printPosSets Debug function. Dump Nullable, firstpos, lastpos and followpos
+// for each node in the tree.
+//
+//-----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBITableBuilder::printPosSets(RBBINode *n) {
+ if (n==NULL) {
+ return;
+ }
+ n->printNode();
+ RBBIDebugPrintf(" Nullable: %s\n", n->fNullable?"TRUE":"FALSE");
+
+ RBBIDebugPrintf(" firstpos: ");
+ printSet(n->fFirstPosSet);
+
+ RBBIDebugPrintf(" lastpos: ");
+ printSet(n->fLastPosSet);
+
+ RBBIDebugPrintf(" followpos: ");
+ printSet(n->fFollowPos);
+
+ printPosSets(n->fLeftChild);
+ printPosSets(n->fRightChild);
+}
+#endif
+
+
+
+//-----------------------------------------------------------------------------
+//
+// getTableSize() Calculate the size of the runtime form of this
+// state transition table.
+//
+//-----------------------------------------------------------------------------
+int32_t RBBITableBuilder::getTableSize() const {
+ int32_t size = 0;
+ int32_t numRows;
+ int32_t numCols;
+ int32_t rowSize;
+
+ if (fTree == NULL) {
+ return 0;
+ }
+
+ size = sizeof(RBBIStateTable) - 4; // The header, with no rows to the table.
+
+ numRows = fDStates->size();
+ numCols = fRB->fSetBuilder->getNumCharCategories();
+
+ // Note The declaration of RBBIStateTableRow is for a table of two columns.
+ // Therefore we subtract two from numCols when determining
+ // how much storage to add to a row for the total columns.
+ rowSize = sizeof(RBBIStateTableRow) + sizeof(uint16_t)*(numCols-2);
+ size += numRows * rowSize;
+ return size;
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// exportTable() export the state transition table in the format required
+// by the runtime engine. getTableSize() bytes of memory
+// must be available at the output address "where".
+//
+//-----------------------------------------------------------------------------
+void RBBITableBuilder::exportTable(void *where) {
+ RBBIStateTable *table = (RBBIStateTable *)where;
+ uint32_t state;
+ int col;
+
+ if (U_FAILURE(*fStatus) || fTree == NULL) {
+ return;
+ }
+
+ if (fRB->fSetBuilder->getNumCharCategories() > 0x7fff ||
+ fDStates->size() > 0x7fff) {
+ *fStatus = U_BRK_INTERNAL_ERROR;
+ return;
+ }
+
+ table->fRowLen = sizeof(RBBIStateTableRow) +
+ sizeof(uint16_t) * (fRB->fSetBuilder->getNumCharCategories() - 2);
+ table->fNumStates = fDStates->size();
+ table->fFlags = 0;
+ if (fRB->fLookAheadHardBreak) {
+ table->fFlags |= RBBI_LOOKAHEAD_HARD_BREAK;
+ }
+ if (fRB->fSetBuilder->sawBOF()) {
+ table->fFlags |= RBBI_BOF_REQUIRED;
+ }
+ table->fReserved = 0;
+
+ for (state=0; statefNumStates; state++) {
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
+ RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen);
+ U_ASSERT (-32768 < sd->fAccepting && sd->fAccepting <= 32767);
+ U_ASSERT (-32768 < sd->fLookAhead && sd->fLookAhead <= 32767);
+ row->fAccepting = (int16_t)sd->fAccepting;
+ row->fLookAhead = (int16_t)sd->fLookAhead;
+ row->fTagIdx = (int16_t)sd->fTagsIdx;
+ for (col=0; colfSetBuilder->getNumCharCategories(); col++) {
+ row->fNextState[col] = (uint16_t)sd->fDtran->elementAti(col);
+ }
+ }
+}
+
+
+
+//-----------------------------------------------------------------------------
+//
+// printSet Debug function. Print the contents of a UVector
+//
+//-----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBITableBuilder::printSet(UVector *s) {
+ int32_t i;
+ for (i=0; isize(); i++) {
+ void *v = s->elementAt(i);
+ RBBIDebugPrintf("%10p", v);
+ }
+ RBBIDebugPrintf("\n");
+}
+#endif
+
+
+//-----------------------------------------------------------------------------
+//
+// printStates Debug Function. Dump the fully constructed state transition table.
+//
+//-----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBITableBuilder::printStates() {
+ int c; // input "character"
+ int n; // state number
+
+ RBBIDebugPrintf("state | i n p u t s y m b o l s \n");
+ RBBIDebugPrintf(" | Acc LA Tag");
+ for (c=0; cfSetBuilder->getNumCharCategories(); c++) {
+ RBBIDebugPrintf(" %2d", c);
+ }
+ RBBIDebugPrintf("\n");
+ RBBIDebugPrintf(" |---------------");
+ for (c=0; cfSetBuilder->getNumCharCategories(); c++) {
+ RBBIDebugPrintf("---");
+ }
+ RBBIDebugPrintf("\n");
+
+ for (n=0; nsize(); n++) {
+ RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
+ RBBIDebugPrintf(" %3d | " , n);
+ RBBIDebugPrintf("%3d %3d %5d ", sd->fAccepting, sd->fLookAhead, sd->fTagsIdx);
+ for (c=0; cfSetBuilder->getNumCharCategories(); c++) {
+ RBBIDebugPrintf(" %2d", sd->fDtran->elementAti(c));
+ }
+ RBBIDebugPrintf("\n");
+ }
+ RBBIDebugPrintf("\n\n");
+}
+#endif
+
+
+
+//-----------------------------------------------------------------------------
+//
+// printRuleStatusTable Debug Function. Dump the common rule status table
+//
+//-----------------------------------------------------------------------------
+#ifdef RBBI_DEBUG
+void RBBITableBuilder::printRuleStatusTable() {
+ int32_t thisRecord = 0;
+ int32_t nextRecord = 0;
+ int i;
+ UVector *tbl = fRB->fRuleStatusVals;
+
+ RBBIDebugPrintf("index | tags \n");
+ RBBIDebugPrintf("-------------------\n");
+
+ while (nextRecord < tbl->size()) {
+ thisRecord = nextRecord;
+ nextRecord = thisRecord + tbl->elementAti(thisRecord) + 1;
+ RBBIDebugPrintf("%4d ", thisRecord);
+ for (i=thisRecord+1; ielementAti(i));
+ }
+ RBBIDebugPrintf("\n");
+ }
+ RBBIDebugPrintf("\n\n");
+}
+#endif
+
+
+//-----------------------------------------------------------------------------
+//
+// RBBIStateDescriptor Methods. This is a very struct-like class
+// Most access is directly to the fields.
+//
+//-----------------------------------------------------------------------------
+
+RBBIStateDescriptor::RBBIStateDescriptor(int lastInputSymbol, UErrorCode *fStatus) {
+ fMarked = FALSE;
+ fAccepting = 0;
+ fLookAhead = 0;
+ fTagsIdx = 0;
+ fTagVals = NULL;
+ fPositions = NULL;
+ fDtran = NULL;
+
+ fDtran = new UVector(lastInputSymbol+1, *fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ if (fDtran == NULL) {
+ *fStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fDtran->setSize(lastInputSymbol+1); // fDtran needs to be pre-sized.
+ // It is indexed by input symbols, and will
+ // hold the next state number for each
+ // symbol.
+}
+
+
+RBBIStateDescriptor::~RBBIStateDescriptor() {
+ delete fPositions;
+ delete fDtran;
+ delete fTagVals;
+ fPositions = NULL;
+ fDtran = NULL;
+ fTagVals = NULL;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/rbbitblb.h b/Build/source/libs/icu/icu-xetex/common/rbbitblb.h
new file mode 100644
index 00000000000..3805b6752a3
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/rbbitblb.h
@@ -0,0 +1,127 @@
+//
+// rbbitblb.h
+//
+
+/*
+**********************************************************************
+* Copyright (c) 2002-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#ifndef RBBITBLB_H
+#define RBBITBLB_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/rbbi.h"
+#include "rbbinode.h"
+
+
+U_NAMESPACE_BEGIN
+
+class RBBIRuleScanner;
+class RBBIRuleBuilder;
+
+//
+// class RBBITableBuilder is part of the RBBI rule compiler.
+// It builds the state transition table used by the RBBI runtime
+// from the expression syntax tree generated by the rule scanner.
+//
+// This class is part of the RBBI implementation only.
+// There is no user-visible public API here.
+//
+
+class RBBITableBuilder : public UMemory {
+public:
+ RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
+ ~RBBITableBuilder();
+
+ void build();
+ int32_t getTableSize() const; // Return the runtime size in bytes of
+ // the built state table
+ void exportTable(void *where); // fill in the runtime state table.
+ // Sufficient memory must exist at
+ // the specified location.
+
+
+private:
+ void calcNullable(RBBINode *n);
+ void calcFirstPos(RBBINode *n);
+ void calcLastPos(RBBINode *n);
+ void calcFollowPos(RBBINode *n);
+ void calcChainedFollowPos(RBBINode *n);
+ void bofFixup();
+ void buildStateTable();
+ void flagAcceptingStates();
+ void flagLookAheadStates();
+ void flagTaggedStates();
+ void mergeRuleStatusVals();
+
+ // Set functions for UVector.
+ // TODO: make a USet subclass of UVector
+
+ void setAdd(UVector *dest, UVector *source);
+ UBool setEquals(UVector *a, UVector *b);
+
+ void sortedAdd(UVector **dest, int32_t val);
+
+public:
+#ifdef RBBI_DEBUG
+ void printSet(UVector *s);
+ void printPosSets(RBBINode *n /* = NULL*/);
+ void printStates();
+ void printRuleStatusTable();
+#else
+ #define printSet(s)
+ #define printPosSets(n)
+ #define printStates()
+ #define printRuleStatusTable()
+#endif
+
+private:
+ RBBIRuleBuilder *fRB;
+ RBBINode *&fTree; // The root node of the parse tree to build a
+ // table for.
+ UErrorCode *fStatus;
+
+ UVector *fDStates; // D states (Aho's terminology)
+ // Index is state number
+ // Contents are RBBIStateDescriptor pointers.
+
+
+ RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
+ RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
+};
+
+//
+// RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
+// one for each state.
+class RBBIStateDescriptor : public UMemory {
+public:
+ UBool fMarked;
+ int32_t fAccepting;
+ int32_t fLookAhead;
+ UVector *fTagVals;
+ int32_t fTagsIdx;
+ UVector *fPositions; // Set of parse tree positions associated
+ // with this state. Unordered (it's a set).
+ // UVector contents are RBBINode *
+
+ UVector *fDtran; // Transitions out of this state.
+ // indexed by input character
+ // contents is int index of dest state
+ // in RBBITableBuilder.fDStates
+
+ RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
+ ~RBBIStateDescriptor();
+
+private:
+ RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
+ RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class
+};
+
+
+
+U_NAMESPACE_END
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/resbund.cpp b/Build/source/libs/icu/icu-xetex/common/resbund.cpp
new file mode 100644
index 00000000000..c4b853293ea
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/resbund.cpp
@@ -0,0 +1,396 @@
+/*
+**********************************************************************
+* Copyright (C) 1997-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+* File resbund.cpp
+*
+* Modification History:
+*
+* Date Name Description
+* 02/05/97 aliu Fixed bug in chopLocale. Added scanForLocaleInFile
+* based on code taken from scanForLocale. Added
+* constructor which attempts to read resource bundle
+* from a specific file, without searching other files.
+* 02/11/97 aliu Added UErrorCode return values to constructors. Fixed
+* infinite loops in scanForFile and scanForLocale.
+* Modified getRawResourceData to not delete storage in
+* localeData and resourceData which it doesn't own.
+* Added Mac compatibility #ifdefs for tellp() and
+* ios::nocreate.
+* 03/04/97 aliu Modified to use ExpandingDataSink objects instead of
+* the highly inefficient ostrstream objects.
+* 03/13/97 aliu Rewrote to load in entire resource bundle and store
+* it as a Hashtable of ResourceBundleData objects.
+* Added state table to govern parsing of files.
+* Modified to load locale index out of new file distinct
+* from default.txt.
+* 03/25/97 aliu Modified to support 2-d arrays, needed for timezone data.
+* Added support for custom file suffixes. Again, needed
+* to support timezone data. Improved error handling to
+* detect duplicate tags and subtags.
+* 04/07/97 aliu Fixed bug in getHashtableForLocale(). Fixed handling
+* of failing UErrorCode values on entry to API methods.
+* Fixed bugs in getArrayItem() for negative indices.
+* 04/29/97 aliu Update to use new Hashtable deletion protocol.
+* 05/06/97 aliu Flattened kTransitionTable for HP compiler.
+* Fixed usage of CharString.
+* 06/11/99 stephen Removed parsing of .txt files.
+* Reworked to use new binary format.
+* Cleaned up.
+* 06/14/99 stephen Removed methods taking a filename suffix.
+* 06/22/99 stephen Added missing T_FileStream_close in parse()
+* 11/09/99 weiv Added getLocale(), rewritten constructForLocale()
+* March 2000 weiv complete overhaul.
+******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/resbund.h"
+#include "umutex.h"
+
+#include "uresimp.h"
+
+U_NAMESPACE_BEGIN
+
+/*-----------------------------------------------------------------------------
+ * Implementation Notes
+ *
+ * Resource bundles are read in once, and thereafter cached.
+ * ResourceBundle statically keeps track of which files have been
+ * read, so we are guaranteed that each file is read at most once.
+ * Resource bundles can be loaded from different data directories and
+ * will be treated as distinct, even if they are for the same locale.
+ *
+ * Resource bundles are lightweight objects, which have pointers to
+ * one or more shared Hashtable objects containing all the data.
+ * Copying would be cheap, but there is no copy constructor, since
+ * there wasn't one in the original API.
+ *
+ * The ResourceBundle parsing mechanism is implemented as a transition
+ * network, for easy maintenance and modification. The network is
+ * implemented as a matrix (instead of in code) to make this even
+ * easier. The matrix contains Transition objects. Each Transition
+ * object describes a destination node and an action to take before
+ * moving to the destination node. The source node is encoded by the
+ * index of the object in the array that contains it. The pieces
+ * needed to understand the transition network are the enums for node
+ * IDs and actions, the parse() method, which walks through the
+ * network and implements the actions, and the network itself. The
+ * network guarantees certain conditions, for example, that a new
+ * resource will not be closed until one has been opened first; or
+ * that data will not be stored into a TaggedList until a TaggedList
+ * has been created. Nonetheless, the code in parse() does some
+ * consistency checks as it runs the network, and fails with an
+ * U_INTERNAL_PROGRAM_ERROR if one of these checks fails. If the input
+ * data has a bad format, an U_INVALID_FORMAT_ERROR is returned. If you
+ * see an U_INTERNAL_PROGRAM_ERROR the transition matrix has a bug in
+ * it.
+ *
+ * Old functionality of multiple locales in a single file is still
+ * supported. For this reason, LOCALE names override FILE names. If
+ * data for en_US is located in the en.txt file, once it is loaded,
+ * the code will not care where it came from (other than remembering
+ * which directory it came from). However, if there is an en_US
+ * resource in en_US.txt, that will take precedence. There is no
+ * limit to the number or type of resources that can be stored in a
+ * file, however, files are only searched in a specific way. If
+ * en_US_CA is requested, then first en_US_CA.txt is searched, then
+ * en_US.txt, then en.txt, then default.txt. So it only makes sense
+ * to put certain locales in certain files. In this example, it would
+ * be logical to put en_US_CA, en_US, and en into the en.txt file,
+ * since they would be found there if asked for. The extreme example
+ * is to place all locale resources into default.txt, which should
+ * also work.
+ *
+ * Inheritance is implemented. For example, xx_YY_zz inherits as
+ * follows: xx_YY_zz, xx_YY, xx, default. Inheritance is implemented
+ * as an array of hashtables. There will be from 1 to 4 hashtables in
+ * the array.
+ *
+ * Fallback files are implemented. The fallback pattern is Language
+ * Country Variant (LCV) -> LC -> L. Fallback is first done for the
+ * requested locale. Then it is done for the default locale, as
+ * returned by Locale::getDefault(). Then the special file
+ * default.txt is searched for the default locale. The overall FILE
+ * fallback path is LCV -> LC -> L -> dLCV -> dLC -> dL -> default.
+ *
+ * Note that although file name searching includes the default locale,
+ * once a ResourceBundle object is constructed, the inheritance path
+ * no longer includes the default locale. The path is LCV -> LC -> L
+ * -> default.
+ *
+ * File parsing is lazy. Nothing is parsed unless it is called for by
+ * someone. So when a ResourceBundle for xx_YY_zz is constructed,
+ * only that locale is parsed (along with anything else in the same
+ * file). Later, if the FooBar tag is asked for, and if it isn't
+ * found in xx_YY_zz, then xx_YY.txt will be parsed and checked, and
+ * so forth, until the chain is exhausted or the tag is found.
+ *
+ * Thread-safety is implemented around caches, both the cache that
+ * stores all the resouce data, and the cache that stores flags
+ * indicating whether or not a file has been visited. These caches
+ * delete their storage at static cleanup time, when the process
+ * quits.
+ *
+ * ResourceBundle supports TableCollation as a special case. This
+ * involves having special ResourceBundle objects which DO own their
+ * data, since we don't want large collation rule strings in the
+ * ResourceBundle cache (these are already cached in the
+ * TableCollation cache). TableCollation files (.ctx files) have the
+ * same format as normal resource data files, with a different
+ * interpretation, from the standpoint of ResourceBundle. .ctx files
+ * are loaded into otherwise ordinary ResourceBundle objects. They
+ * don't inherit (that's implemented by TableCollation) and they own
+ * their data (as mentioned above). However, they still support
+ * possible multiple locales in a single .ctx file. (This is in
+ * practice a bad idea, since you only want the one locale you're
+ * looking for, and only one tag will be present
+ * ("CollationElements"), so you don't need an inheritance chain of
+ * multiple locales.) Up to 4 locale resources will be loaded from a
+ * .ctx file; everything after the first 4 is ignored (parsed and
+ * deleted). (Normal .txt files have no limit.) Instead of being
+ * loaded into the cache, and then looked up as needed, the locale
+ * resources are read straight into the ResourceBundle object.
+ *
+ * The Index, which used to reside in default.txt, has been moved to a
+ * new file, index.txt. This file contains a slightly modified format
+ * with the addition of the "InstalledLocales" tag; it looks like:
+ *
+ * Index {
+ * InstalledLocales {
+ * ar
+ * ..
+ * zh_TW
+ * }
+ * }
+ */
+//-----------------------------------------------------------------------------
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ResourceBundle)
+
+ResourceBundle::ResourceBundle(UErrorCode &err)
+ :UObject(), fLocale(NULL)
+{
+ fResource = ures_open(0, Locale::getDefault().getName(), &err);
+}
+
+ResourceBundle::ResourceBundle(const ResourceBundle &other)
+ :UObject(other), fLocale(NULL)
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (other.fResource) {
+ fResource = ures_copyResb(0, other.fResource, &status);
+ } else {
+ /* Copying a bad resource bundle */
+ fResource = NULL;
+ }
+}
+
+ResourceBundle::ResourceBundle(UResourceBundle *res, UErrorCode& err)
+ :UObject(), fLocale(NULL)
+{
+ if (res) {
+ fResource = ures_copyResb(0, res, &err);
+ } else {
+ /* Copying a bad resource bundle */
+ fResource = NULL;
+ }
+}
+
+ResourceBundle::ResourceBundle(const char* path, const Locale& locale, UErrorCode& err)
+ :UObject(), fLocale(NULL)
+{
+ fResource = ures_open(path, locale.getName(), &err);
+}
+
+
+ResourceBundle& ResourceBundle::operator=(const ResourceBundle& other)
+{
+ if(this == &other) {
+ return *this;
+ }
+ if(fResource != 0) {
+ ures_close(fResource);
+ fResource = NULL;
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ if (other.fResource) {
+ fResource = ures_copyResb(0, other.fResource, &status);
+ } else {
+ /* Copying a bad resource bundle */
+ fResource = NULL;
+ }
+ return *this;
+}
+
+ResourceBundle::~ResourceBundle()
+{
+ if(fResource != 0) {
+ ures_close(fResource);
+ }
+ if(fLocale != NULL) {
+ delete(fLocale);
+ }
+}
+
+ResourceBundle *
+ResourceBundle::clone() const {
+ return new ResourceBundle(*this);
+}
+
+UnicodeString ResourceBundle::getString(UErrorCode& status) const {
+ int32_t len = 0;
+ const UChar *r = ures_getString(fResource, &len, &status);
+ return UnicodeString(TRUE, r, len);
+}
+
+const uint8_t *ResourceBundle::getBinary(int32_t& len, UErrorCode& status) const {
+ return ures_getBinary(fResource, &len, &status);
+}
+
+const int32_t *ResourceBundle::getIntVector(int32_t& len, UErrorCode& status) const {
+ return ures_getIntVector(fResource, &len, &status);
+}
+
+uint32_t ResourceBundle::getUInt(UErrorCode& status) const {
+ return ures_getUInt(fResource, &status);
+}
+
+int32_t ResourceBundle::getInt(UErrorCode& status) const {
+ return ures_getInt(fResource, &status);
+}
+
+const char *ResourceBundle::getName(void) const {
+ return ures_getName(fResource);
+}
+
+const char *ResourceBundle::getKey(void) const {
+ return ures_getKey(fResource);
+}
+
+UResType ResourceBundle::getType(void) const {
+ return ures_getType(fResource);
+}
+
+int32_t ResourceBundle::getSize(void) const {
+ return ures_getSize(fResource);
+}
+
+UBool ResourceBundle::hasNext(void) const {
+ return ures_hasNext(fResource);
+}
+
+void ResourceBundle::resetIterator(void) {
+ ures_resetIterator(fResource);
+}
+
+ResourceBundle ResourceBundle::getNext(UErrorCode& status) {
+ UResourceBundle r;
+
+ ures_initStackObject(&r);
+ ures_getNextResource(fResource, &r, &status);
+ ResourceBundle res(&r, status);
+ if (U_SUCCESS(status)) {
+ ures_close(&r);
+ }
+ return res;
+}
+
+UnicodeString ResourceBundle::getNextString(UErrorCode& status) {
+ int32_t len = 0;
+ const UChar* r = ures_getNextString(fResource, &len, 0, &status);
+ return UnicodeString(TRUE, r, len);
+}
+
+UnicodeString ResourceBundle::getNextString(const char ** key, UErrorCode& status) {
+ int32_t len = 0;
+ const UChar* r = ures_getNextString(fResource, &len, key, &status);
+ return UnicodeString(TRUE, r, len);
+}
+
+ResourceBundle ResourceBundle::get(int32_t indexR, UErrorCode& status) const {
+ UResourceBundle r;
+
+ ures_initStackObject(&r);
+ ures_getByIndex(fResource, indexR, &r, &status);
+ ResourceBundle res(&r, status);
+ if (U_SUCCESS(status)) {
+ ures_close(&r);
+ }
+ return res;
+}
+
+UnicodeString ResourceBundle::getStringEx(int32_t indexS, UErrorCode& status) const {
+ int32_t len = 0;
+ const UChar* r = ures_getStringByIndex(fResource, indexS, &len, &status);
+ return UnicodeString(TRUE, r, len);
+}
+
+ResourceBundle ResourceBundle::get(const char* key, UErrorCode& status) const {
+ UResourceBundle r;
+
+ ures_initStackObject(&r);
+ ures_getByKey(fResource, key, &r, &status);
+ ResourceBundle res(&r, status);
+ if (U_SUCCESS(status)) {
+ ures_close(&r);
+ }
+ return res;
+}
+
+ResourceBundle ResourceBundle::getWithFallback(const char* key, UErrorCode& status){
+ UResourceBundle r;
+ ures_initStackObject(&r);
+ ures_getByKeyWithFallback(fResource, key, &r, &status);
+ ResourceBundle res(&r, status);
+ if(U_SUCCESS(status)){
+ ures_close(&r);
+ }
+ return res;
+}
+UnicodeString ResourceBundle::getStringEx(const char* key, UErrorCode& status) const {
+ int32_t len = 0;
+ const UChar* r = ures_getStringByKey(fResource, key, &len, &status);
+ return UnicodeString(TRUE, r, len);
+}
+
+const char*
+ResourceBundle::getVersionNumber() const
+{
+ return ures_getVersionNumber(fResource);
+}
+
+void ResourceBundle::getVersion(UVersionInfo versionInfo) const {
+ ures_getVersion(fResource, versionInfo);
+}
+
+const Locale &ResourceBundle::getLocale(void) const
+{
+ UBool needInit;
+ UMTX_CHECK(NULL, (fLocale == NULL), needInit);
+ if(needInit) {
+ UErrorCode status = U_ZERO_ERROR;
+ const char *localeName = ures_getLocale(fResource, &status);
+ Locale *tLocale = new Locale(localeName);
+ umtx_lock(NULL);
+ ResourceBundle *me = (ResourceBundle *)this; // semantically const
+ if (me->fLocale == NULL) {
+ me->fLocale = tLocale;
+ tLocale = NULL;
+ }
+ umtx_unlock(NULL);
+ delete tLocale;
+ }
+ return *fLocale;
+}
+
+const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
+{
+ return ures_getLocaleByType(fResource, type, &status);
+}
+
+//eof
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/resbund_cnv.cpp b/Build/source/libs/icu/icu-xetex/common/resbund_cnv.cpp
new file mode 100644
index 00000000000..a18e57e3106
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/resbund_cnv.cpp
@@ -0,0 +1,55 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 1997-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: resbund_cnv.cpp
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004aug25
+* created by: Markus W. Scherer
+*
+* Character conversion functions moved here from resbund.cpp
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/resbund.h"
+#include "uinvchar.h"
+
+U_NAMESPACE_BEGIN
+
+ResourceBundle::ResourceBundle( const UnicodeString& path,
+ const Locale& locale,
+ UErrorCode& error)
+ :UObject(), fLocale(NULL)
+{
+ constructForLocale(path, locale, error);
+}
+
+ResourceBundle::ResourceBundle( const UnicodeString& path,
+ UErrorCode& error)
+ :UObject(), fLocale(NULL)
+{
+ constructForLocale(path, Locale::getDefault(), error);
+}
+
+void
+ResourceBundle::constructForLocale(const UnicodeString& path,
+ const Locale& locale,
+ UErrorCode& error)
+{
+ if (path.isEmpty()) {
+ fResource = ures_open(NULL, locale.getName(), &error);
+ }
+ else {
+ UnicodeString nullTerminatedPath(path);
+ nullTerminatedPath.append((UChar)0);
+ fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error);
+ }
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/ruleiter.cpp b/Build/source/libs/icu/icu-xetex/common/ruleiter.cpp
new file mode 100644
index 00000000000..b99a831513d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ruleiter.cpp
@@ -0,0 +1,160 @@
+/*
+**********************************************************************
+* Copyright (c) 2003-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: September 24 2003
+* Since: ICU 2.8
+**********************************************************************
+*/
+#include "ruleiter.h"
+#include "unicode/parsepos.h"
+#include "unicode/unistr.h"
+#include "unicode/symtable.h"
+#include "util.h"
+
+/* \U87654321 or \ud800\udc00 */
+#define MAX_U_NOTATION_LEN 12
+
+U_NAMESPACE_BEGIN
+
+RuleCharacterIterator::RuleCharacterIterator(const UnicodeString& theText, const SymbolTable* theSym,
+ ParsePosition& thePos) :
+ text(theText),
+ pos(thePos),
+ sym(theSym),
+ buf(0),
+ bufPos(0)
+{}
+
+UBool RuleCharacterIterator::atEnd() const {
+ return buf == 0 && pos.getIndex() == text.length();
+}
+
+UChar32 RuleCharacterIterator::next(int32_t options, UBool& isEscaped, UErrorCode& ec) {
+ if (U_FAILURE(ec)) return DONE;
+
+ UChar32 c = DONE;
+ isEscaped = FALSE;
+
+ for (;;) {
+ c = _current();
+ _advance(UTF_CHAR_LENGTH(c));
+
+ if (c == SymbolTable::SYMBOL_REF && buf == 0 &&
+ (options & PARSE_VARIABLES) != 0 && sym != 0) {
+ UnicodeString name = sym->parseReference(text, pos, text.length());
+ // If name is empty there was an isolated SYMBOL_REF;
+ // return it. Caller must be prepared for this.
+ if (name.length() == 0) {
+ break;
+ }
+ bufPos = 0;
+ buf = sym->lookup(name);
+ if (buf == 0) {
+ ec = U_UNDEFINED_VARIABLE;
+ return DONE;
+ }
+ // Handle empty variable value
+ if (buf->length() == 0) {
+ buf = 0;
+ }
+ continue;
+ }
+
+ if ((options & SKIP_WHITESPACE) != 0 &&
+ uprv_isRuleWhiteSpace(c)) {
+ continue;
+ }
+
+ if (c == 0x5C /*'\\'*/ && (options & PARSE_ESCAPES) != 0) {
+ UnicodeString tempEscape;
+ int32_t offset = 0;
+ c = lookahead(tempEscape, MAX_U_NOTATION_LEN).unescapeAt(offset);
+ jumpahead(offset);
+ isEscaped = TRUE;
+ if (c < 0) {
+ ec = U_MALFORMED_UNICODE_ESCAPE;
+ return DONE;
+ }
+ }
+
+ break;
+ }
+
+ return c;
+}
+
+void RuleCharacterIterator::getPos(RuleCharacterIterator::Pos& p) const {
+ p.buf = buf;
+ p.pos = pos.getIndex();
+ p.bufPos = bufPos;
+}
+
+void RuleCharacterIterator::setPos(const RuleCharacterIterator::Pos& p) {
+ buf = p.buf;
+ pos.setIndex(p.pos);
+ bufPos = p.bufPos;
+}
+
+void RuleCharacterIterator::skipIgnored(int32_t options) {
+ if ((options & SKIP_WHITESPACE) != 0) {
+ for (;;) {
+ UChar32 a = _current();
+ if (!uprv_isRuleWhiteSpace(a)) break;
+ _advance(UTF_CHAR_LENGTH(a));
+ }
+ }
+}
+
+UnicodeString& RuleCharacterIterator::lookahead(UnicodeString& result, int32_t maxLookAhead) const {
+ if (maxLookAhead < 0) {
+ maxLookAhead = 0x7FFFFFFF;
+ }
+ if (buf != 0) {
+ buf->extract(bufPos, maxLookAhead, result);
+ } else {
+ text.extract(pos.getIndex(), maxLookAhead, result);
+ }
+ return result;
+}
+
+void RuleCharacterIterator::jumpahead(int32_t count) {
+ _advance(count);
+}
+
+/*
+UnicodeString& RuleCharacterIterator::toString(UnicodeString& result) const {
+ int32_t b = pos.getIndex();
+ text.extract(0, b, result);
+ return result.append((UChar) 0x7C).append(text, b, 0x7FFFFFFF); // Insert '|' at index
+}
+*/
+
+UChar32 RuleCharacterIterator::_current() const {
+ if (buf != 0) {
+ return buf->char32At(bufPos);
+ } else {
+ int i = pos.getIndex();
+ return (i < text.length()) ? text.char32At(i) : (UChar32)DONE;
+ }
+}
+
+void RuleCharacterIterator::_advance(int32_t count) {
+ if (buf != 0) {
+ bufPos += count;
+ if (bufPos == buf->length()) {
+ buf = 0;
+ }
+ } else {
+ pos.setIndex(pos.getIndex() + count);
+ if (pos.getIndex() > text.length()) {
+ pos.setIndex(text.length());
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/ruleiter.h b/Build/source/libs/icu/icu-xetex/common/ruleiter.h
new file mode 100644
index 00000000000..cc4e8475fd2
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ruleiter.h
@@ -0,0 +1,232 @@
+/*
+**********************************************************************
+* Copyright (c) 2003-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: September 24 2003
+* Since: ICU 2.8
+**********************************************************************
+*/
+#ifndef _RULEITER_H_
+#define _RULEITER_H_
+
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeString;
+class ParsePosition;
+class SymbolTable;
+
+/**
+ * An iterator that returns 32-bit code points. This class is deliberately
+ * not related to any of the ICU character iterator classes
+ * in order to minimize complexity.
+ * @author Alan Liu
+ * @since ICU 2.8
+ */
+class RuleCharacterIterator : public UMemory {
+
+ // TODO: Ideas for later. (Do not implement if not needed, lest the
+ // code coverage numbers go down due to unused methods.)
+ // 1. Add a copy constructor, operator==() method.
+ // 2. Rather than return DONE, throw an exception if the end
+ // is reached -- this is an alternate usage model, probably not useful.
+
+private:
+ /**
+ * Text being iterated.
+ */
+ const UnicodeString& text;
+
+ /**
+ * Position of iterator.
+ */
+ ParsePosition& pos;
+
+ /**
+ * Symbol table used to parse and dereference variables. May be 0.
+ */
+ const SymbolTable* sym;
+
+ /**
+ * Current variable expansion, or 0 if none.
+ */
+ const UnicodeString* buf;
+
+ /**
+ * Position within buf. Meaningless if buf == 0.
+ */
+ int32_t bufPos;
+
+public:
+ /**
+ * Value returned when there are no more characters to iterate.
+ */
+ enum { DONE = -1 };
+
+ /**
+ * Bitmask option to enable parsing of variable names. If (options &
+ * PARSE_VARIABLES) != 0, then an embedded variable will be expanded to
+ * its value. Variables are parsed using the SymbolTable API.
+ */
+ enum { PARSE_VARIABLES = 1 };
+
+ /**
+ * Bitmask option to enable parsing of escape sequences. If (options &
+ * PARSE_ESCAPES) != 0, then an embedded escape sequence will be expanded
+ * to its value. Escapes are parsed using Utility.unescapeAt().
+ */
+ enum { PARSE_ESCAPES = 2 };
+
+ /**
+ * Bitmask option to enable skipping of whitespace. If (options &
+ * SKIP_WHITESPACE) != 0, then whitespace characters will be silently
+ * skipped, as if they were not present in the input. Whitespace
+ * characters are defined by UCharacterProperty.isRuleWhiteSpace().
+ */
+ enum { SKIP_WHITESPACE = 4 };
+
+ /**
+ * Constructs an iterator over the given text, starting at the given
+ * position.
+ * @param text the text to be iterated
+ * @param sym the symbol table, or null if there is none. If sym is null,
+ * then variables will not be deferenced, even if the PARSE_VARIABLES
+ * option is set.
+ * @param pos upon input, the index of the next character to return. If a
+ * variable has been dereferenced, then pos will not increment as
+ * characters of the variable value are iterated.
+ */
+ RuleCharacterIterator(const UnicodeString& text, const SymbolTable* sym,
+ ParsePosition& pos);
+
+ /**
+ * Returns true if this iterator has no more characters to return.
+ */
+ UBool atEnd() const;
+
+ /**
+ * Returns the next character using the given options, or DONE if there
+ * are no more characters, and advance the position to the next
+ * character.
+ * @param options one or more of the following options, bitwise-OR-ed
+ * together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.
+ * @param isEscaped output parameter set to TRUE if the character
+ * was escaped
+ * @param ec input-output error code. An error will only be set by
+ * this routing if options includes PARSE_VARIABLES and an unknown
+ * variable name is seen, or if options includes PARSE_ESCAPES and
+ * an invalid escape sequence is seen.
+ * @return the current 32-bit code point, or DONE
+ */
+ UChar32 next(int32_t options, UBool& isEscaped, UErrorCode& ec);
+
+ /**
+ * Returns true if this iterator is currently within a variable expansion.
+ */
+ inline UBool inVariable() const;
+
+ /**
+ * An opaque object representing the position of a RuleCharacterIterator.
+ */
+ struct Pos : public UMemory {
+ private:
+ const UnicodeString* buf;
+ int32_t pos;
+ int32_t bufPos;
+ friend class RuleCharacterIterator;
+ };
+
+ /**
+ * Sets an object which, when later passed to setPos(), will
+ * restore this iterator's position. Usage idiom:
+ *
+ * RuleCharacterIterator iterator = ...;
+ * RuleCharacterIterator::Pos pos;
+ * iterator.getPos(pos);
+ * for (;;) {
+ * iterator.getPos(pos);
+ * int c = iterator.next(...);
+ * ...
+ * }
+ * iterator.setPos(pos);
+ *
+ * @param p a position object to be set to this iterator's
+ * current position.
+ */
+ void getPos(Pos& p) const;
+
+ /**
+ * Restores this iterator to the position it had when getPos()
+ * set the given object.
+ * @param p a position object previously set by getPos()
+ */
+ void setPos(const Pos& p);
+
+ /**
+ * Skips ahead past any ignored characters, as indicated by the given
+ * options. This is useful in conjunction with the lookahead() method.
+ *
+ * Currently, this only has an effect for SKIP_WHITESPACE.
+ * @param options one or more of the following options, bitwise-OR-ed
+ * together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.
+ */
+ void skipIgnored(int32_t options);
+
+ /**
+ * Returns a string containing the remainder of the characters to be
+ * returned by this iterator, without any option processing. If the
+ * iterator is currently within a variable expansion, this will only
+ * extend to the end of the variable expansion. This method is provided
+ * so that iterators may interoperate with string-based APIs. The typical
+ * sequence of calls is to call skipIgnored(), then call lookahead(), then
+ * parse the string returned by lookahead(), then call jumpahead() to
+ * resynchronize the iterator.
+ * @param result a string to receive the characters to be returned
+ * by future calls to next()
+ * @param maxLookAhead The maximum to copy into the result.
+ * @return a reference to result
+ */
+ UnicodeString& lookahead(UnicodeString& result, int32_t maxLookAhead = -1) const;
+
+ /**
+ * Advances the position by the given number of 16-bit code units.
+ * This is useful in conjunction with the lookahead() method.
+ * @param count the number of 16-bit code units to jump over
+ */
+ void jumpahead(int32_t count);
+
+ /**
+ * Returns a string representation of this object, consisting of the
+ * characters being iterated, with a '|' marking the current position.
+ * Position within an expanded variable is not indicated.
+ * @param result output parameter to receive a string
+ * representation of this object
+ */
+// UnicodeString& toString(UnicodeString& result) const;
+
+private:
+ /**
+ * Returns the current 32-bit code point without parsing escapes, parsing
+ * variables, or skipping whitespace.
+ * @return the current 32-bit code point
+ */
+ UChar32 _current() const;
+
+ /**
+ * Advances the position by the given amount.
+ * @param count the number of 16-bit code units to advance past
+ */
+ void _advance(int32_t count);
+};
+
+inline UBool RuleCharacterIterator::inVariable() const {
+ return buf != 0;
+}
+
+U_NAMESPACE_END
+
+#endif // _RULEITER_H_
+//eof
diff --git a/Build/source/libs/icu/icu-xetex/common/schriter.cpp b/Build/source/libs/icu/icu-xetex/common/schriter.cpp
new file mode 100644
index 00000000000..29f15f9749e
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/schriter.cpp
@@ -0,0 +1,115 @@
+/*
+******************************************************************************
+* Copyright (C) 1998-2004, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+******************************************************************************
+*
+* File schriter.cpp
+*
+* Modification History:
+*
+* Date Name Description
+* 05/05/99 stephen Cleaned up.
+******************************************************************************
+*/
+
+#include "unicode/chariter.h"
+#include "unicode/schriter.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
+
+StringCharacterIterator::StringCharacterIterator()
+ : UCharCharacterIterator(),
+ text()
+{
+ // NEVER DEFAULT CONSTRUCT!
+}
+
+StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr)
+ : UCharCharacterIterator(textStr.fArray, textStr.length()),
+ text(textStr)
+{
+ // we had set the input parameter's array, now we need to set our copy's array
+ UCharCharacterIterator::text = this->text.fArray;
+}
+
+StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
+ int32_t textPos)
+ : UCharCharacterIterator(textStr.fArray, textStr.length(), textPos),
+ text(textStr)
+{
+ // we had set the input parameter's array, now we need to set our copy's array
+ UCharCharacterIterator::text = this->text.fArray;
+}
+
+StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
+ int32_t textBegin,
+ int32_t textEnd,
+ int32_t textPos)
+ : UCharCharacterIterator(textStr.fArray, textStr.length(), textBegin, textEnd, textPos),
+ text(textStr)
+{
+ // we had set the input parameter's array, now we need to set our copy's array
+ UCharCharacterIterator::text = this->text.fArray;
+}
+
+StringCharacterIterator::StringCharacterIterator(const StringCharacterIterator& that)
+ : UCharCharacterIterator(that),
+ text(that.text)
+{
+ // we had set the input parameter's array, now we need to set our copy's array
+ UCharCharacterIterator::text = this->text.fArray;
+}
+
+StringCharacterIterator::~StringCharacterIterator() {
+}
+
+StringCharacterIterator&
+StringCharacterIterator::operator=(const StringCharacterIterator& that) {
+ UCharCharacterIterator::operator=(that);
+ text = that.text;
+ // we had set the input parameter's array, now we need to set our copy's array
+ UCharCharacterIterator::text = this->text.fArray;
+ return *this;
+}
+
+UBool
+StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+
+ // do not call UCharCharacterIterator::operator==()
+ // because that checks for array pointer equality
+ // while we compare UnicodeString objects
+
+ if (getDynamicClassID() != that.getDynamicClassID()) {
+ return FALSE;
+ }
+
+ StringCharacterIterator& realThat = (StringCharacterIterator&)that;
+
+ return text == realThat.text
+ && pos == realThat.pos
+ && begin == realThat.begin
+ && end == realThat.end;
+}
+
+CharacterIterator*
+StringCharacterIterator::clone() const {
+ return new StringCharacterIterator(*this);
+}
+
+void
+StringCharacterIterator::setText(const UnicodeString& newText) {
+ text = newText;
+ UCharCharacterIterator::setText(text.fArray, text.length());
+}
+
+void
+StringCharacterIterator::getText(UnicodeString& result) {
+ result = text;
+}
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/serv.cpp b/Build/source/libs/icu/icu-xetex/common/serv.cpp
new file mode 100644
index 00000000000..8dc15b2c0fa
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/serv.cpp
@@ -0,0 +1,974 @@
+/**
+*******************************************************************************
+* Copyright (C) 2001-2007, International Business Machines Corporation. *
+* All Rights Reserved. *
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "serv.h"
+#include "umutex.h"
+
+#undef SERVICE_REFCOUNT
+
+// in case we use the refcount stuff
+
+U_NAMESPACE_BEGIN
+
+/*
+******************************************************************
+*/
+
+const UChar ICUServiceKey::PREFIX_DELIMITER = 0x002F; /* '/' */
+
+ICUServiceKey::ICUServiceKey(const UnicodeString& id)
+: _id(id) {
+}
+
+ICUServiceKey::~ICUServiceKey()
+{
+}
+
+const UnicodeString&
+ICUServiceKey::getID() const
+{
+ return _id;
+}
+
+UnicodeString&
+ICUServiceKey::canonicalID(UnicodeString& result) const
+{
+ return result.append(_id);
+}
+
+UnicodeString&
+ICUServiceKey::currentID(UnicodeString& result) const
+{
+ return canonicalID(result);
+}
+
+UnicodeString&
+ICUServiceKey::currentDescriptor(UnicodeString& result) const
+{
+ prefix(result);
+ result.append(PREFIX_DELIMITER);
+ return currentID(result);
+}
+
+UBool
+ICUServiceKey::fallback()
+{
+ return FALSE;
+}
+
+UBool
+ICUServiceKey::isFallbackOf(const UnicodeString& id) const
+{
+ return id == _id;
+}
+
+UnicodeString&
+ICUServiceKey::prefix(UnicodeString& result) const
+{
+ return result;
+}
+
+UnicodeString&
+ICUServiceKey::parsePrefix(UnicodeString& result)
+{
+ int32_t n = result.indexOf(PREFIX_DELIMITER);
+ if (n < 0) {
+ n = 0;
+ }
+ result.remove(n);
+ return result;
+}
+
+UnicodeString&
+ICUServiceKey::parseSuffix(UnicodeString& result)
+{
+ int32_t n = result.indexOf(PREFIX_DELIMITER);
+ if (n >= 0) {
+ result.remove(0, n+1);
+ }
+ return result;
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+ICUServiceKey::debug(UnicodeString& result) const
+{
+ debugClass(result);
+ result.append(" id: ");
+ result.append(_id);
+ return result;
+}
+
+UnicodeString&
+ICUServiceKey::debugClass(UnicodeString& result) const
+{
+ return result.append("ICUServiceKey");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUServiceKey)
+
+/*
+******************************************************************
+*/
+
+SimpleFactory::SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible)
+: _instance(instanceToAdopt), _id(id), _visible(visible)
+{
+}
+
+SimpleFactory::~SimpleFactory()
+{
+ delete _instance;
+}
+
+UObject*
+SimpleFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ UnicodeString temp;
+ if (_id == key.currentID(temp)) {
+ return service->cloneInstance(_instance);
+ }
+ }
+ return NULL;
+}
+
+void
+SimpleFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
+{
+ if (_visible) {
+ result.put(_id, (void*)this, status); // cast away const
+ } else {
+ result.remove(_id);
+ }
+}
+
+UnicodeString&
+SimpleFactory::getDisplayName(const UnicodeString& id, const Locale& /* locale */, UnicodeString& result) const
+{
+ if (_visible && _id == id) {
+ result = _id;
+ } else {
+ result.setToBogus();
+ }
+ return result;
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+SimpleFactory::debug(UnicodeString& toAppendTo) const
+{
+ debugClass(toAppendTo);
+ toAppendTo.append(" id: ");
+ toAppendTo.append(_id);
+ toAppendTo.append(", visible: ");
+ toAppendTo.append(_visible ? "T" : "F");
+ return toAppendTo;
+}
+
+UnicodeString&
+SimpleFactory::debugClass(UnicodeString& toAppendTo) const
+{
+ return toAppendTo.append("SimpleFactory");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleFactory)
+
+/*
+******************************************************************
+*/
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ServiceListener)
+
+/*
+******************************************************************
+*/
+
+// Record the actual id for this service in the cache, so we can return it
+// even if we succeed later with a different id.
+class CacheEntry : public UMemory {
+private:
+ int32_t refcount;
+
+public:
+ UnicodeString actualDescriptor;
+ UObject* service;
+
+ /**
+ * Releases a reference to the shared resource.
+ */
+ ~CacheEntry() {
+ delete service;
+ }
+
+ CacheEntry(const UnicodeString& _actualDescriptor, UObject* _service)
+ : refcount(1), actualDescriptor(_actualDescriptor), service(_service) {
+ }
+
+ /**
+ * Instantiation creates an initial reference, so don't call this
+ * unless you're creating a new pointer to this. Management of
+ * that pointer will have to know how to deal with refcounts.
+ * Return true if the resource has not already been released.
+ */
+ CacheEntry* ref() {
+ ++refcount;
+ return this;
+ }
+
+ /**
+ * Destructions removes a reference, so don't call this unless
+ * you're removing pointer to this somewhere. Management of that
+ * pointer will have to know how to deal with refcounts. Once
+ * the refcount drops to zero, the resource is released. Return
+ * false if the resouce has been released.
+ */
+ CacheEntry* unref() {
+ if ((--refcount) == 0) {
+ delete this;
+ return NULL;
+ }
+ return this;
+ }
+
+ /**
+ * Return TRUE if there is at least one reference to this and the
+ * resource has not been released.
+ */
+ UBool isShared() const {
+ return refcount > 1;
+ }
+};
+
+// UObjectDeleter for serviceCache
+U_CDECL_BEGIN
+static void U_CALLCONV
+cacheDeleter(void* obj) {
+ U_NAMESPACE_USE ((CacheEntry*)obj)->unref();
+}
+
+/**
+* Deleter for UObjects
+*/
+static void U_CALLCONV
+deleteUObject(void *obj) {
+ U_NAMESPACE_USE delete (UObject*) obj;
+}
+U_CDECL_END
+
+/*
+******************************************************************
+*/
+
+class DNCache : public UMemory {
+public:
+ Hashtable cache;
+ const Locale locale;
+
+ DNCache(const Locale& _locale)
+ : cache(), locale(_locale)
+ {
+ // cache.setKeyDeleter(uhash_deleteUnicodeString);
+ }
+};
+
+
+/*
+******************************************************************
+*/
+
+StringPair*
+StringPair::create(const UnicodeString& displayName,
+ const UnicodeString& id,
+ UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ StringPair* sp = new StringPair(displayName, id);
+ if (sp == NULL || sp->isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete sp;
+ return NULL;
+ }
+ return sp;
+ }
+ return NULL;
+}
+
+UBool
+StringPair::isBogus() const {
+ return displayName.isBogus() || id.isBogus();
+}
+
+StringPair::StringPair(const UnicodeString& _displayName,
+ const UnicodeString& _id)
+: displayName(_displayName)
+, id(_id)
+{
+}
+
+U_CDECL_BEGIN
+static void U_CALLCONV
+userv_deleteStringPair(void *obj) {
+ U_NAMESPACE_USE delete (StringPair*) obj;
+}
+U_CDECL_END
+
+/*
+******************************************************************
+*/
+
+ICUService::ICUService()
+: name()
+, lock(0)
+, timestamp(0)
+, factories(NULL)
+, serviceCache(NULL)
+, idCache(NULL)
+, dnCache(NULL)
+{
+ umtx_init(&lock);
+}
+
+ICUService::ICUService(const UnicodeString& newName)
+: name(newName)
+, lock(0)
+, timestamp(0)
+, factories(NULL)
+, serviceCache(NULL)
+, idCache(NULL)
+, dnCache(NULL)
+{
+ umtx_init(&lock);
+}
+
+ICUService::~ICUService()
+{
+ {
+ Mutex mutex(&lock);
+ clearCaches();
+ delete factories;
+ factories = NULL;
+ }
+ umtx_destroy(&lock);
+}
+
+UObject*
+ICUService::get(const UnicodeString& descriptor, UErrorCode& status) const
+{
+ return get(descriptor, NULL, status);
+}
+
+UObject*
+ICUService::get(const UnicodeString& descriptor, UnicodeString* actualReturn, UErrorCode& status) const
+{
+ UObject* result = NULL;
+ ICUServiceKey* key = createKey(&descriptor, status);
+ if (key) {
+ result = getKey(*key, actualReturn, status);
+ delete key;
+ }
+ return result;
+}
+
+UObject*
+ICUService::getKey(ICUServiceKey& key, UErrorCode& status) const
+{
+ return getKey(key, NULL, status);
+}
+
+// this is a vector that subclasses of ICUService can override to further customize the result object
+// before returning it. All other public get functions should call this one.
+
+UObject*
+ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const
+{
+ return getKey(key, actualReturn, NULL, status);
+}
+
+// make it possible to call reentrantly on systems that don't have reentrant mutexes.
+// we can use this simple approach since we know the situation where we're calling
+// reentrantly even without knowing the thread.
+class XMutex : public UMemory {
+public:
+ inline XMutex(UMTX *mutex, UBool reentering)
+ : fMutex(mutex)
+ , fActive(!reentering)
+ {
+ if (fActive) umtx_lock(fMutex);
+ }
+ inline ~XMutex() {
+ if (fActive) umtx_unlock(fMutex);
+ }
+
+private:
+ UMTX *fMutex;
+ UBool fActive;
+};
+
+struct UVectorDeleter {
+ UVector* _obj;
+ UVectorDeleter() : _obj(NULL) {}
+ ~UVectorDeleter() { delete _obj; }
+};
+
+// called only by factories, treat as private
+UObject*
+ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUServiceFactory* factory, UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if (isDefault()) {
+ return handleDefault(key, actualReturn, status);
+ }
+
+ ICUService* ncthis = (ICUService*)this; // cast away semantic const
+
+ CacheEntry* result = NULL;
+ {
+ // The factory list can't be modified until we're done,
+ // otherwise we might update the cache with an invalid result.
+ // The cache has to stay in synch with the factory list.
+ // ICU doesn't have monitors so we can't use rw locks, so
+ // we single-thread everything using this service, for now.
+
+ // if factory is not null, we're calling from within the mutex,
+ // and since some unix machines don't have reentrant mutexes we
+ // need to make sure not to try to lock it again.
+ XMutex mutex(&ncthis->lock, factory != NULL);
+
+ if (serviceCache == NULL) {
+ ncthis->serviceCache = new Hashtable(status);
+ if (U_FAILURE(status)) {
+ delete serviceCache;
+ return NULL;
+ }
+ serviceCache->setValueDeleter(cacheDeleter);
+ }
+
+ UnicodeString currentDescriptor;
+ UVectorDeleter cacheDescriptorList;
+ UBool putInCache = FALSE;
+
+ int32_t startIndex = 0;
+ int32_t limit = factories->size();
+ UBool cacheResult = TRUE;
+
+ if (factory != NULL) {
+ for (int32_t i = 0; i < limit; ++i) {
+ if (factory == (const ICUServiceFactory*)factories->elementAt(i)) {
+ startIndex = i + 1;
+ break;
+ }
+ }
+ if (startIndex == 0) {
+ // throw new InternalError("Factory " + factory + "not registered with service: " + this);
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ cacheResult = FALSE;
+ }
+
+ do {
+ currentDescriptor.remove();
+ key.currentDescriptor(currentDescriptor);
+ result = (CacheEntry*)serviceCache->get(currentDescriptor);
+ if (result != NULL) {
+ break;
+ }
+
+ // first test of cache failed, so we'll have to update
+ // the cache if we eventually succeed-- that is, if we're
+ // going to update the cache at all.
+ putInCache = TRUE;
+
+ int32_t index = startIndex;
+ while (index < limit) {
+ ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(index++);
+ UObject* service = f->create(key, this, status);
+ if (U_FAILURE(status)) {
+ delete service;
+ return NULL;
+ }
+ if (service != NULL) {
+ result = new CacheEntry(currentDescriptor, service);
+ if (result == NULL) {
+ delete service;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ goto outerEnd;
+ }
+ }
+
+ // prepare to load the cache with all additional ids that
+ // will resolve to result, assuming we'll succeed. We
+ // don't want to keep querying on an id that's going to
+ // fallback to the one that succeeded, we want to hit the
+ // cache the first time next goaround.
+ if (cacheDescriptorList._obj == NULL) {
+ cacheDescriptorList._obj = new UVector(uhash_deleteUnicodeString, NULL, 5, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ }
+ UnicodeString* idToCache = new UnicodeString(currentDescriptor);
+ if (idToCache == NULL || idToCache->isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ cacheDescriptorList._obj->addElement(idToCache, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ } while (key.fallback());
+outerEnd:
+
+ if (result != NULL) {
+ if (putInCache && cacheResult) {
+ serviceCache->put(result->actualDescriptor, result, status);
+ if (U_FAILURE(status)) {
+ delete result;
+ return NULL;
+ }
+
+ if (cacheDescriptorList._obj != NULL) {
+ for (int32_t i = cacheDescriptorList._obj->size(); --i >= 0;) {
+ UnicodeString* desc = (UnicodeString*)cacheDescriptorList._obj->elementAt(i);
+ serviceCache->put(*desc, result, status);
+ if (U_FAILURE(status)) {
+ delete result;
+ return NULL;
+ }
+
+ result->ref();
+ cacheDescriptorList._obj->removeElementAt(i);
+ }
+ }
+ }
+
+ if (actualReturn != NULL) {
+ // strip null prefix
+ if (result->actualDescriptor.indexOf((UChar)0x2f) == 0) { // U+002f=slash (/)
+ actualReturn->remove();
+ actualReturn->append(result->actualDescriptor,
+ 1,
+ result->actualDescriptor.length() - 1);
+ } else {
+ *actualReturn = result->actualDescriptor;
+ }
+
+ if (actualReturn->isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete result;
+ return NULL;
+ }
+ }
+
+ UObject* service = cloneInstance(result->service);
+ if (putInCache && !cacheResult) {
+ delete result;
+ }
+ return service;
+ }
+ }
+
+ return handleDefault(key, actualReturn, status);
+}
+
+UObject*
+ICUService::handleDefault(const ICUServiceKey& /* key */, UnicodeString* /* actualIDReturn */, UErrorCode& /* status */) const
+{
+ return NULL;
+}
+
+UVector&
+ICUService::getVisibleIDs(UVector& result, UErrorCode& status) const {
+ return getVisibleIDs(result, NULL, status);
+}
+
+UVector&
+ICUService::getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorCode& status) const
+{
+ result.removeAllElements();
+
+ if (U_FAILURE(status)) {
+ return result;
+ }
+
+ ICUService * ncthis = (ICUService*)this; // cast away semantic const
+ {
+ Mutex mutex(&ncthis->lock);
+ const Hashtable* map = getVisibleIDMap(status);
+ if (map != NULL) {
+ ICUServiceKey* fallbackKey = createKey(matchID, status);
+
+ for (int32_t pos = -1;;) {
+ const UHashElement* e = map->nextElement(pos);
+ if (e == NULL) {
+ break;
+ }
+
+ const UnicodeString* id = (const UnicodeString*)e->key.pointer;
+ if (fallbackKey != NULL) {
+ if (!fallbackKey->isFallbackOf(*id)) {
+ continue;
+ }
+ }
+
+ UnicodeString* idClone = new UnicodeString(*id);
+ if (idClone == NULL || idClone->isBogus()) {
+ delete idClone;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ result.addElement(idClone, status);
+ if (U_FAILURE(status)) {
+ delete idClone;
+ break;
+ }
+ }
+ delete fallbackKey;
+ }
+ }
+ if (U_FAILURE(status)) {
+ result.removeAllElements();
+ }
+ return result;
+}
+
+const Hashtable*
+ICUService::getVisibleIDMap(UErrorCode& status) const {
+ if (U_FAILURE(status)) return NULL;
+
+ // must only be called when lock is already held
+
+ ICUService* ncthis = (ICUService*)this; // cast away semantic const
+ if (idCache == NULL) {
+ ncthis->idCache = new Hashtable(status);
+ if (idCache == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else if (factories != NULL) {
+ for (int32_t pos = factories->size(); --pos >= 0;) {
+ ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(pos);
+ f->updateVisibleIDs(*idCache, status);
+ }
+ if (U_FAILURE(status)) {
+ delete idCache;
+ ncthis->idCache = NULL;
+ }
+ }
+ }
+
+ return idCache;
+}
+
+
+UnicodeString&
+ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result) const
+{
+ return getDisplayName(id, result, Locale::getDefault());
+}
+
+UnicodeString&
+ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const Locale& locale) const
+{
+ {
+ ICUService* ncthis = (ICUService*)this; // cast away semantic const
+ UErrorCode status = U_ZERO_ERROR;
+ Mutex mutex(&ncthis->lock);
+ const Hashtable* map = getVisibleIDMap(status);
+ if (map != NULL) {
+ ICUServiceFactory* f = (ICUServiceFactory*)map->get(id);
+ if (f != NULL) {
+ f->getDisplayName(id, locale, result);
+ return result;
+ }
+
+ // fallback
+ UErrorCode status = U_ZERO_ERROR;
+ ICUServiceKey* fallbackKey = createKey(&id, status);
+ while (fallbackKey->fallback()) {
+ UnicodeString us;
+ fallbackKey->currentID(us);
+ f = (ICUServiceFactory*)map->get(us);
+ if (f != NULL) {
+ f->getDisplayName(id, locale, result);
+ delete fallbackKey;
+ return result;
+ }
+ }
+ delete fallbackKey;
+ }
+ }
+ result.setToBogus();
+ return result;
+}
+
+UVector&
+ICUService::getDisplayNames(UVector& result, UErrorCode& status) const
+{
+ return getDisplayNames(result, Locale::getDefault(), NULL, status);
+}
+
+
+UVector&
+ICUService::getDisplayNames(UVector& result, const Locale& locale, UErrorCode& status) const
+{
+ return getDisplayNames(result, locale, NULL, status);
+}
+
+UVector&
+ICUService::getDisplayNames(UVector& result,
+ const Locale& locale,
+ const UnicodeString* matchID,
+ UErrorCode& status) const
+{
+ result.removeAllElements();
+ result.setDeleter(userv_deleteStringPair);
+ if (U_SUCCESS(status)) {
+ ICUService* ncthis = (ICUService*)this; // cast away semantic const
+ Mutex mutex(&ncthis->lock);
+
+ if (dnCache != NULL && dnCache->locale != locale) {
+ delete dnCache;
+ ncthis->dnCache = NULL;
+ }
+
+ if (dnCache == NULL) {
+ const Hashtable* m = getVisibleIDMap(status);
+ if (m != NULL) {
+ ncthis->dnCache = new DNCache(locale);
+ if (dnCache == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return result;
+ }
+
+ int32_t pos = 0;
+ const UHashElement* entry = NULL;
+ while ((entry = m->nextElement(pos)) != NULL) {
+ const UnicodeString* id = (const UnicodeString*)entry->key.pointer;
+ ICUServiceFactory* f = (ICUServiceFactory*)entry->value.pointer;
+ UnicodeString dname;
+ f->getDisplayName(*id, locale, dname);
+ if (dname.isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ dnCache->cache.put(dname, (void*)id, status); // share pointer with visibleIDMap
+ if (U_SUCCESS(status)) {
+ continue;
+ }
+ }
+ delete dnCache;
+ ncthis->dnCache = NULL;
+ return result;
+ }
+ }
+ }
+ }
+
+ ICUServiceKey* matchKey = createKey(matchID, status);
+ int32_t pos = 0;
+ const UHashElement *entry = NULL;
+ while ((entry = dnCache->cache.nextElement(pos)) != NULL) {
+ const UnicodeString* id = (const UnicodeString*)entry->value.pointer;
+ if (matchKey != NULL && !matchKey->isFallbackOf(*id)) {
+ continue;
+ }
+ const UnicodeString* dn = (const UnicodeString*)entry->key.pointer;
+ StringPair* sp = StringPair::create(*id, *dn, status);
+ result.addElement(sp, status);
+ if (U_FAILURE(status)) {
+ result.removeAllElements();
+ break;
+ }
+ }
+ delete matchKey;
+
+ return result;
+}
+
+URegistryKey
+ICUService::registerInstance(UObject* objToAdopt, const UnicodeString& id, UErrorCode& status)
+{
+ return registerInstance(objToAdopt, id, TRUE, status);
+}
+
+URegistryKey
+ICUService::registerInstance(UObject* objToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status)
+{
+ ICUServiceKey* key = createKey(&id, status);
+ if (key != NULL) {
+ UnicodeString canonicalID;
+ key->canonicalID(canonicalID);
+ delete key;
+
+ ICUServiceFactory* f = createSimpleFactory(objToAdopt, canonicalID, visible, status);
+ if (f != NULL) {
+ return registerFactory(f, status);
+ }
+ }
+ delete objToAdopt;
+ return NULL;
+}
+
+ICUServiceFactory*
+ICUService::createSimpleFactory(UObject* objToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if ((objToAdopt != NULL) && (!id.isBogus())) {
+ return new SimpleFactory(objToAdopt, id, visible);
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+}
+
+URegistryKey
+ICUService::registerFactory(ICUServiceFactory* factoryToAdopt, UErrorCode& status)
+{
+ if (U_SUCCESS(status) && factoryToAdopt != NULL) {
+ Mutex mutex(&lock);
+
+ if (factories == NULL) {
+ factories = new UVector(deleteUObject, NULL, status);
+ if (U_FAILURE(status)) {
+ delete factories;
+ return NULL;
+ }
+ }
+ factories->insertElementAt(factoryToAdopt, 0, status);
+ if (U_SUCCESS(status)) {
+ clearCaches();
+ } else {
+ delete factoryToAdopt;
+ factoryToAdopt = NULL;
+ }
+ }
+
+ if (factoryToAdopt != NULL) {
+ notifyChanged();
+ }
+
+ return (URegistryKey)factoryToAdopt;
+}
+
+UBool
+ICUService::unregister(URegistryKey rkey, UErrorCode& status)
+{
+ ICUServiceFactory *factory = (ICUServiceFactory*)rkey;
+ UBool result = FALSE;
+ if (factory != NULL && factories != NULL) {
+ Mutex mutex(&lock);
+
+ if (factories->removeElement(factory)) {
+ clearCaches();
+ result = TRUE;
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ delete factory;
+ }
+ }
+ if (result) {
+ notifyChanged();
+ }
+ return result;
+}
+
+void
+ICUService::reset()
+{
+ {
+ Mutex mutex(&lock);
+ reInitializeFactories();
+ clearCaches();
+ }
+ notifyChanged();
+}
+
+void
+ICUService::reInitializeFactories()
+{
+ if (factories != NULL) {
+ factories->removeAllElements();
+ }
+}
+
+UBool
+ICUService::isDefault() const
+{
+ return countFactories() == 0;
+}
+
+ICUServiceKey*
+ICUService::createKey(const UnicodeString* id, UErrorCode& status) const
+{
+ return (U_FAILURE(status) || id == NULL) ? NULL : new ICUServiceKey(*id);
+}
+
+void
+ICUService::clearCaches()
+{
+ // callers synchronize before use
+ ++timestamp;
+ delete dnCache;
+ dnCache = NULL;
+ delete idCache;
+ idCache = NULL;
+ delete serviceCache; serviceCache = NULL;
+}
+
+void
+ICUService::clearServiceCache()
+{
+ // callers synchronize before use
+ delete serviceCache; serviceCache = NULL;
+}
+
+UBool
+ICUService::acceptsListener(const EventListener& l) const
+{
+ return l.getDynamicClassID() == ServiceListener::getStaticClassID();
+}
+
+void
+ICUService::notifyListener(EventListener& l) const
+{
+ ((ServiceListener&)l).serviceChanged(*this);
+}
+
+UnicodeString&
+ICUService::getName(UnicodeString& result) const
+{
+ return result.append(name);
+}
+
+int32_t
+ICUService::countFactories() const
+{
+ return factories == NULL ? 0 : factories->size();
+}
+
+int32_t
+ICUService::getTimestamp() const
+{
+ return timestamp;
+}
+
+U_NAMESPACE_END
+
+/* UCONFIG_NO_SERVICE */
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/serv.h b/Build/source/libs/icu/icu-xetex/common/serv.h
new file mode 100644
index 00000000000..2e498fb4a05
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/serv.h
@@ -0,0 +1,996 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2007, International Business Machines Corporation. *
+ * All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef ICUSERV_H
+#define ICUSERV_H
+
+#include "unicode/utypes.h"
+
+#if UCONFIG_NO_SERVICE
+
+U_NAMESPACE_BEGIN
+
+/*
+ * Allow the declaration of APIs with pointers to ICUService
+ * even when service is removed from the build.
+ */
+class ICUService;
+
+U_NAMESPACE_END
+
+#else
+
+#include "unicode/unistr.h"
+#include "unicode/locid.h"
+#include "unicode/umisc.h"
+
+#include "hash.h"
+#include "uvector.h"
+#include "servnotf.h"
+
+class ICUServiceTest;
+
+U_NAMESPACE_BEGIN
+
+class ICUServiceKey;
+class ICUServiceFactory;
+class SimpleFactory;
+class ServiceListener;
+class ICUService;
+
+class DNCache;
+
+/*******************************************************************
+ * ICUServiceKey
+ */
+
+/**
+ * ICUServiceKeys are used to communicate with factories to
+ * generate an instance of the service. ICUServiceKeys define how
+ * ids are canonicalized, provide both a current id and a current
+ * descriptor to use in querying the cache and factories, and
+ * determine the fallback strategy.
+ *
+ * ICUServiceKeys provide both a currentDescriptor and a currentID.
+ * The descriptor contains an optional prefix, followed by '/'
+ * and the currentID. Factories that handle complex keys,
+ * for example number format factories that generate multiple
+ * kinds of formatters for the same locale, use the descriptor
+ * to provide a fully unique identifier for the service object,
+ * while using the currentID (in this case, the locale string),
+ * as the visible IDs that can be localized.
+ *
+ * The default implementation of ICUServiceKey has no fallbacks and
+ * has no custom descriptors.
+ */
+class U_COMMON_API ICUServiceKey : public UObject {
+ private:
+ const UnicodeString _id;
+
+ protected:
+ static const UChar PREFIX_DELIMITER;
+
+ public:
+
+ /**
+ * Construct a key from an id.
+ *
+ * @param id the ID from which to construct the key.
+ */
+ ICUServiceKey(const UnicodeString& id);
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~ICUServiceKey();
+
+ /**
+ * Return the original ID used to construct this key.
+ *
+ * @return the ID used to construct this key.
+ */
+ virtual const UnicodeString& getID() const;
+
+ /**
+ * Return the canonical version of the original ID. This implementation
+ * appends the original ID to result. Result is returned as a convenience.
+ *
+ * @param result the output parameter to which the id will be appended.
+ * @return the modified result.
+ */
+ virtual UnicodeString& canonicalID(UnicodeString& result) const;
+
+ /**
+ * Return the (canonical) current ID. This implementation appends
+ * the canonical ID to result. Result is returned as a convenience.
+ *
+ * @param result the output parameter to which the current id will be appended.
+ * @return the modified result.
+ */
+ virtual UnicodeString& currentID(UnicodeString& result) const;
+
+ /**
+ * Return the current descriptor. This implementation appends
+ * the current descriptor to result. Result is returned as a convenience.
+ *
+ * The current descriptor is used to fully
+ * identify an instance of the service in the cache. A
+ * factory may handle all descriptors for an ID, or just a
+ * particular descriptor. The factory can either parse the
+ * descriptor or use custom API on the key in order to
+ * instantiate the service.
+ *
+ * @param result the output parameter to which the current id will be appended.
+ * @return the modified result.
+ */
+ virtual UnicodeString& currentDescriptor(UnicodeString& result) const;
+
+ /**
+ * If the key has a fallback, modify the key and return true,
+ * otherwise return false. The current ID will change if there
+ * is a fallback. No currentIDs should be repeated, and fallback
+ * must eventually return false. This implementation has no fallbacks
+ * and always returns false.
+ *
+ * @return TRUE if the ICUServiceKey changed to a valid fallback value.
+ */
+ virtual UBool fallback();
+
+ /**
+ * Return TRUE if a key created from id matches, or would eventually
+ * fallback to match, the canonical ID of this ICUServiceKey.
+ *
+ * @param id the id to test.
+ * @return TRUE if this ICUServiceKey's canonical ID is a fallback of id.
+ */
+ virtual UBool isFallbackOf(const UnicodeString& id) const;
+
+ /**
+ * Return the prefix. This implementation leaves result unchanged.
+ * Result is returned as a convenience.
+ *
+ * @param result the output parameter to which the prefix will be appended.
+ * @return the modified result.
+ */
+ virtual UnicodeString& prefix(UnicodeString& result) const;
+
+ /**
+ * A utility to parse the prefix out of a descriptor string. Only
+ * the (undelimited) prefix, if any, remains in result. Result is returned as a
+ * convenience.
+ *
+ * @param result an input/output parameter that on entry is a descriptor, and
+ * on exit is the prefix of that descriptor.
+ * @return the modified result.
+ */
+ static UnicodeString& parsePrefix(UnicodeString& result);
+
+ /**
+ * A utility to parse the suffix out of a descriptor string. Only
+ * the (undelimited) suffix, if any, remains in result. Result is returned as a
+ * convenience.
+ *
+ * @param result an input/output parameter that on entry is a descriptor, and
+ * on exit is the suffix of that descriptor.
+ * @return the modified result.
+ */
+ static UnicodeString& parseSuffix(UnicodeString& result);
+
+public:
+ /**
+ * UObject RTTI boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * UObject RTTI boilerplate.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& result) const;
+ virtual UnicodeString& debugClass(UnicodeString& result) const;
+#endif
+
+};
+
+ /*******************************************************************
+ * ICUServiceFactory
+ */
+
+ /**
+ * An implementing ICUServiceFactory generates the service objects maintained by the
+ * service. A factory generates a service object from a key,
+ * updates id->factory mappings, and returns the display name for
+ * a supported id.
+ */
+class U_COMMON_API ICUServiceFactory : public UObject {
+ public:
+
+ /**
+ * Create a service object from the key, if this factory
+ * supports the key. Otherwise, return NULL.
+ *
+ * If the factory supports the key, then it can call
+ * the service's getKey(ICUServiceKey, String[], ICUServiceFactory) method
+ * passing itself as the factory to get the object that
+ * the service would have created prior to the factory's
+ * registration with the service. This can change the
+ * key, so any information required from the key should
+ * be extracted before making such a callback.
+ *
+ * @param key the service key.
+ * @param service the service with which this factory is registered.
+ * @param status the error code status.
+ * @return the service object, or NULL if the factory does not support the key.
+ */
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const = 0;
+
+ /**
+ * Update result to reflect the IDs (not descriptors) that this
+ * factory publicly handles. Result contains mappings from ID to
+ * factory. On entry it will contain all (visible) mappings from
+ * previously-registered factories.
+ *
+ * This function, together with getDisplayName, are used to
+ * support ICUService::getDisplayNames. The factory determines
+ * which IDs (of those it supports) it will make visible, and of
+ * those, which it will provide localized display names for. In
+ * most cases it will register mappings from all IDs it supports
+ * to itself.
+ *
+ * @param result the mapping table to update.
+ * @param status the error code status.
+ */
+ virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const = 0;
+
+ /**
+ * Return, in result, the display name of the id in the provided locale.
+ * This is an id, not a descriptor. If the id is
+ * not visible, sets result to bogus. If the
+ * incoming result is bogus, it remains bogus. Result is returned as a
+ * convenience. Results are not defined if id is not one supported by this
+ * factory.
+ *
+ * @param id a visible id supported by this factory.
+ * @param locale the locale for which to generate the corresponding localized display name.
+ * @param result output parameter to hold the display name.
+ * @return result.
+ */
+ virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const = 0;
+};
+
+/*
+ ******************************************************************
+ */
+
+ /**
+ * A default implementation of factory. This provides default
+ * implementations for subclasses, and implements a singleton
+ * factory that matches a single ID and returns a single
+ * (possibly deferred-initialized) instance. This implements
+ * updateVisibleIDs to add a mapping from its ID to itself
+ * if visible is true, or to remove any existing mapping
+ * for its ID if visible is false. No localization of display
+ * names is performed.
+ */
+class U_COMMON_API SimpleFactory : public ICUServiceFactory {
+ protected:
+ UObject* _instance;
+ const UnicodeString _id;
+ const UBool _visible;
+
+ public:
+ /**
+ * Construct a SimpleFactory that maps a single ID to a single
+ * service instance. If visible is TRUE, the ID will be visible.
+ * The instance must not be NULL. The SimpleFactory will adopt
+ * the instance, which must not be changed subsequent to this call.
+ *
+ * @param instanceToAdopt the service instance to adopt.
+ * @param id the ID to assign to this service instance.
+ * @param visible if TRUE, the ID will be visible.
+ */
+ SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible = TRUE);
+
+ /**
+ * Destructor.
+ */
+ virtual ~SimpleFactory();
+
+ /**
+ * This implementation returns a clone of the service instance if the factory's ID is equal to
+ * the key's currentID. Service and prefix are ignored.
+ *
+ * @param key the service key.
+ * @param service the service with which this factory is registered.
+ * @param status the error code status.
+ * @return the service object, or NULL if the factory does not support the key.
+ */
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
+
+ /**
+ * This implementation adds a mapping from ID -> this to result if visible is TRUE,
+ * otherwise it removes ID from result.
+ *
+ * @param result the mapping table to update.
+ * @param status the error code status.
+ */
+ virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const;
+
+ /**
+ * This implementation returns the factory ID if it equals id and visible is TRUE,
+ * otherwise it returns the empty string. (This implementation provides
+ * no localized id information.)
+ *
+ * @param id a visible id supported by this factory.
+ * @param locale the locale for which to generate the corresponding localized display name.
+ * @param result output parameter to hold the display name.
+ * @return result.
+ */
+ virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
+
+public:
+ /**
+ * UObject RTTI boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * UObject RTTI boilerplate.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& toAppendTo) const;
+ virtual UnicodeString& debugClass(UnicodeString& toAppendTo) const;
+#endif
+
+};
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * ServiceListener is the listener that ICUService provides by default.
+ * ICUService will notifiy this listener when factories are added to
+ * or removed from the service. Subclasses can provide
+ * different listener interfaces that extend EventListener, and modify
+ * acceptsListener and notifyListener as appropriate.
+ */
+class U_COMMON_API ServiceListener : public EventListener {
+public:
+ /**
+ * This method is called when the service changes. At the time of the
+ * call this listener is registered with the service. It must
+ * not modify the notifier in the context of this call.
+ *
+ * @param service the service that changed.
+ */
+ virtual void serviceChanged(const ICUService& service) const = 0;
+
+public:
+ /**
+ * UObject RTTI boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * UObject RTTI boilerplate.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+};
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * A StringPair holds a displayName/ID pair. ICUService uses it
+ * as the array elements returned by getDisplayNames.
+ */
+class U_COMMON_API StringPair : public UMemory {
+public:
+ /**
+ *
The display name of the pair.
+ */
+ const UnicodeString displayName;
+
+ /**
+ * The ID of the pair.
+ */
+ const UnicodeString id;
+
+ /**
+ * Creates a string pair from a displayName and an ID.
+ *
+ * @param displayName the displayName.
+ * @param id the ID.
+ * @param status the error code status.
+ * @return a StringPair if the creation was successful, otherwise NULL.
+ */
+ static StringPair* create(const UnicodeString& displayName,
+ const UnicodeString& id,
+ UErrorCode& status);
+
+ /**
+ * Return TRUE if either string of the pair is bogus.
+ * @return TRUE if either string of the pair is bogus.
+ */
+ UBool isBogus() const;
+
+private:
+ StringPair(const UnicodeString& displayName, const UnicodeString& id);
+};
+
+/*******************************************************************
+ * ICUService
+ */
+
+ /**
+ * A Service provides access to service objects that implement a
+ * particular service, e.g. transliterators. Users provide a String
+ * id (for example, a locale string) to the service, and get back an
+ * object for that id. Service objects can be any kind of object. A
+ * new service object is returned for each query. The caller is
+ * responsible for deleting it.
+ *
+ * Services 'canonicalize' the query ID and use the canonical ID to
+ * query for the service. The service also defines a mechanism to
+ * 'fallback' the ID multiple times. Clients can optionally request
+ * the actual ID that was matched by a query when they use an ID to
+ * retrieve a service object.
+ *
+ * Service objects are instantiated by ICUServiceFactory objects
+ * registered with the service. The service queries each
+ * ICUServiceFactory in turn, from most recently registered to
+ * earliest registered, until one returns a service object. If none
+ * responds with a service object, a fallback ID is generated, and the
+ * process repeats until a service object is returned or until the ID
+ * has no further fallbacks.
+ *
+ * In ICU 2.4, UObject (the base class of service instances) does
+ * not define a polymorphic clone function. ICUService uses clones to
+ * manage ownership. Thus, for now, ICUService defines an abstract
+ * method, cloneInstance, that clients must implement to create clones
+ * of the service instances. This may change in future releases of
+ * ICU.
+ *
+ * ICUServiceFactories can be dynamically registered and
+ * unregistered with the service. When registered, an
+ * ICUServiceFactory is installed at the head of the factory list, and
+ * so gets 'first crack' at any keys or fallback keys. When
+ * unregistered, it is removed from the service and can no longer be
+ * located through it. Service objects generated by this factory and
+ * held by the client are unaffected.
+ *
+ * If a service has variants (e.g., the different variants of
+ * BreakIterator) an ICUServiceFactory can use the prefix of the
+ * ICUServiceKey to determine the variant of a service to generate.
+ * If it does not support all variants, it can request
+ * previously-registered factories to handle the ones it does not
+ * support.
+ *
+ * ICUService uses ICUServiceKeys to query factories and perform
+ * fallback. The ICUServiceKey defines the canonical form of the ID,
+ * and implements the fallback strategy. Custom ICUServiceKeys can be
+ * defined that parse complex IDs into components that
+ * ICUServiceFactories can more easily use. The ICUServiceKey can
+ * cache the results of this parsing to save repeated effort.
+ * ICUService provides convenience APIs that take UnicodeStrings and
+ * generate default ICUServiceKeys for use in querying.
+ *
+ * ICUService provides API to get the list of IDs publicly
+ * supported by the service (although queries aren't restricted to
+ * this list). This list contains only 'simple' IDs, and not fully
+ * unique IDs. ICUServiceFactories are associated with each simple ID
+ * and the responsible factory can also return a human-readable
+ * localized version of the simple ID, for use in user interfaces.
+ * ICUService can also provide an array of the all the localized
+ * visible IDs and their corresponding internal IDs.
+ *
+ * ICUService implements ICUNotifier, so that clients can register
+ * to receive notification when factories are added or removed from
+ * the service. ICUService provides a default EventListener
+ * subinterface, ServiceListener, which can be registered with the
+ * service. When the service changes, the ServiceListener's
+ * serviceChanged method is called with the service as the
+ * argument.
+ *
+ * The ICUService API is both rich and generic, and it is expected
+ * that most implementations will statically 'wrap' ICUService to
+ * present a more appropriate API-- for example, to declare the type
+ * of the objects returned from get, to limit the factories that can
+ * be registered with the service, or to define their own listener
+ * interface with a custom callback method. They might also customize
+ * ICUService by overriding it, for example, to customize the
+ * ICUServiceKey and fallback strategy. ICULocaleService is a
+ * subclass of ICUService that uses Locale names as IDs and uses
+ * ICUServiceKeys that implement the standard resource bundle fallback
+ * strategy. Most clients will wish to subclass it instead of
+ * ICUService.
+ */
+class U_COMMON_API ICUService : public ICUNotifier {
+ protected:
+ /**
+ * Name useful for debugging.
+ */
+ const UnicodeString name;
+
+ private:
+
+ /**
+ * single lock used by this service.
+ */
+ UMTX lock;
+
+ /**
+ * Timestamp so iterators can be fail-fast.
+ */
+ uint32_t timestamp;
+
+ /**
+ * All the factories registered with this service.
+ */
+ UVector* factories;
+
+ /**
+ * The service cache.
+ */
+ Hashtable* serviceCache;
+
+ /**
+ * The ID cache.
+ */
+ Hashtable* idCache;
+
+ /**
+ * The name cache.
+ */
+ DNCache* dnCache;
+
+ /**
+ * Constructor.
+ */
+ public:
+ /**
+ * Construct a new ICUService.
+ */
+ ICUService();
+
+ /**
+ * Construct with a name (useful for debugging).
+ *
+ * @param name a name to use in debugging.
+ */
+ ICUService(const UnicodeString& name);
+
+ /**
+ * Destructor.
+ */
+ virtual ~ICUService();
+
+ /**
+ * Return the name of this service. This will be the empty string if none was assigned.
+ * Returns result as a convenience.
+ *
+ * @param result an output parameter to contain the name of this service.
+ * @return the name of this service.
+ */
+ UnicodeString& getName(UnicodeString& result) const;
+
+ /**
+ * Convenience override for get(ICUServiceKey&, UnicodeString*). This uses
+ * createKey to create a key for the provided descriptor.
+ *
+ * @param descriptor the descriptor.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ UObject* get(const UnicodeString& descriptor, UErrorCode& status) const;
+
+ /**
+ * Convenience override for get(ICUServiceKey&, UnicodeString*). This uses
+ * createKey to create a key from the provided descriptor.
+ *
+ * @param descriptor the descriptor.
+ * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ UObject* get(const UnicodeString& descriptor, UnicodeString* actualReturn, UErrorCode& status) const;
+
+ /**
+ * Convenience override for get(ICUServiceKey&, UnicodeString*).
+ *
+ * @param key the key.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ UObject* getKey(ICUServiceKey& key, UErrorCode& status) const;
+
+ /**
+ * Given a key, return a service object, and, if actualReturn
+ * is not NULL, the descriptor with which it was found in the
+ * first element of actualReturn. If no service object matches
+ * this key, returns NULL and leaves actualReturn unchanged.
+ *
+ * This queries the cache using the key's descriptor, and if no
+ * object in the cache matches, tries the key on each
+ * registered factory, in order. If none generates a service
+ * object for the key, repeats the process with each fallback of
+ * the key, until either a factory returns a service object, or the key
+ * has no fallback. If no object is found, the result of handleDefault
+ * is returned.
+ *
+ * Subclasses can override this method to further customize the
+ * result before returning it.
+ *
+ * @param key the key.
+ * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const;
+
+ /**
+ *
This version of getKey is only called by ICUServiceFactories within the scope
+ * of a previous getKey call, to determine what previously-registered factories would
+ * have returned. For details, see getKey(ICUServiceKey&, UErrorCode&). Subclasses
+ * should not call it directly, but call through one of the other get functions.
+ *
+ * @param key the key.
+ * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL.
+ * @param factory the factory making the recursive call.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUServiceFactory* factory, UErrorCode& status) const;
+
+ /**
+ * Convenience override for getVisibleIDs(String) that passes null
+ * as the fallback, thus returning all visible IDs.
+ *
+ * @param result a vector to hold the returned IDs.
+ * @param status the error code status.
+ * @return the result vector.
+ */
+ UVector& getVisibleIDs(UVector& result, UErrorCode& status) const;
+
+ /**
+ * Return a snapshot of the visible IDs for this service. This
+ * list will not change as ICUServiceFactories are added or removed, but the
+ * supported IDs will, so there is no guarantee that all and only
+ * the IDs in the returned list will be visible and supported by the
+ * service in subsequent calls.
+ *
+ * The IDs are returned as pointers to UnicodeStrings. The
+ * caller owns the IDs. Previous contents of result are discarded before
+ * new elements, if any, are added.
+ *
+ * matchID is passed to createKey to create a key. If the key
+ * is not NULL, its isFallbackOf method is used to filter out IDs
+ * that don't match the key or have it as a fallback.
+ *
+ * @param result a vector to hold the returned IDs.
+ * @param matchID an ID used to filter the result, or NULL if all IDs are desired.
+ * @param status the error code status.
+ * @return the result vector.
+ */
+ UVector& getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorCode& status) const;
+
+ /**
+ * Convenience override for getDisplayName(const UnicodeString&, const Locale&, UnicodeString&) that
+ * uses the current default locale.
+ *
+ * @param id the ID for which to retrieve the localized displayName.
+ * @param result an output parameter to hold the display name.
+ * @return the modified result.
+ */
+ UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result) const;
+
+ /**
+ * Given a visible ID, return the display name in the requested locale.
+ * If there is no directly supported ID corresponding to this ID, result is
+ * set to bogus.
+ *
+ * @param id the ID for which to retrieve the localized displayName.
+ * @param result an output parameter to hold the display name.
+ * @param locale the locale in which to localize the ID.
+ * @return the modified result.
+ */
+ UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result, const Locale& locale) const;
+
+ /**
+ * Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that
+ * uses the current default Locale as the locale and NULL for
+ * the matchID.
+ *
+ * @param result a vector to hold the returned displayName/id StringPairs.
+ * @param status the error code status.
+ * @return the modified result vector.
+ */
+ UVector& getDisplayNames(UVector& result, UErrorCode& status) const;
+
+ /**
+ * Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that
+ * uses NULL for the matchID.
+ *
+ * @param result a vector to hold the returned displayName/id StringPairs.
+ * @param locale the locale in which to localize the ID.
+ * @param status the error code status.
+ * @return the modified result vector.
+ */
+ UVector& getDisplayNames(UVector& result, const Locale& locale, UErrorCode& status) const;
+
+ /**
+ * Return a snapshot of the mapping from display names to visible
+ * IDs for this service. This set will not change as factories
+ * are added or removed, but the supported IDs will, so there is
+ * no guarantee that all and only the IDs in the returned map will
+ * be visible and supported by the service in subsequent calls,
+ * nor is there any guarantee that the current display names match
+ * those in the result.
+ *
+ * The names are returned as pointers to StringPairs, which
+ * contain both the displayName and the corresponding ID. The
+ * caller owns the StringPairs. Previous contents of result are
+ * discarded before new elements, if any, are added.
+ *
+ * matchID is passed to createKey to create a key. If the key
+ * is not NULL, its isFallbackOf method is used to filter out IDs
+ * that don't match the key or have it as a fallback.
+ *
+ * @param result a vector to hold the returned displayName/id StringPairs.
+ * @param locale the locale in which to localize the ID.
+ * @param matchID an ID used to filter the result, or NULL if all IDs are desired.
+ * @param status the error code status.
+ * @return the result vector. */
+ UVector& getDisplayNames(UVector& result,
+ const Locale& locale,
+ const UnicodeString* matchID,
+ UErrorCode& status) const;
+
+ /**
+ * A convenience override of registerInstance(UObject*, const UnicodeString&, UBool)
+ * that defaults visible to TRUE.
+ *
+ * @param objToAdopt the object to register and adopt.
+ * @param id the ID to assign to this object.
+ * @param status the error code status.
+ * @return a registry key that can be passed to unregister to unregister
+ * (and discard) this instance.
+ */
+ URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UErrorCode& status);
+
+ /**
+ * Register a service instance with the provided ID. The ID will be
+ * canonicalized. The canonicalized ID will be returned by
+ * getVisibleIDs if visible is TRUE. The service instance will be adopted and
+ * must not be modified subsequent to this call.
+ *
+ * This issues a serviceChanged notification to registered listeners.
+ *
+ * This implementation wraps the object using
+ * createSimpleFactory, and calls registerFactory.
+ *
+ * @param objToAdopt the object to register and adopt.
+ * @param id the ID to assign to this object.
+ * @param visible TRUE if getVisibleIDs is to return this ID.
+ * @param status the error code status.
+ * @return a registry key that can be passed to unregister() to unregister
+ * (and discard) this instance.
+ */
+ virtual URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status);
+
+ /**
+ * Register an ICUServiceFactory. Returns a registry key that
+ * can be used to unregister the factory. The factory
+ * must not be modified subsequent to this call. The service owns
+ * all registered factories. In case of an error, the factory is
+ * deleted.
+ *
+ * This issues a serviceChanged notification to registered listeners.
+ *
+ * The default implementation accepts all factories.
+ *
+ * @param factoryToAdopt the factory to register and adopt.
+ * @param status the error code status.
+ * @return a registry key that can be passed to unregister to unregister
+ * (and discard) this factory.
+ */
+ virtual URegistryKey registerFactory(ICUServiceFactory* factoryToAdopt, UErrorCode& status);
+
+ /**
+ * Unregister a factory using a registry key returned by
+ * registerInstance or registerFactory. After a successful call,
+ * the factory will be removed from the service factory list and
+ * deleted, and the key becomes invalid.
+ *
+ * This issues a serviceChanged notification to registered
+ * listeners.
+ *
+ * @param rkey the registry key.
+ * @param status the error code status.
+ * @return TRUE if the call successfully unregistered the factory.
+ */
+ virtual UBool unregister(URegistryKey rkey, UErrorCode& status);
+
+ /**
+ *
Reset the service to the default factories. The factory
+ * lock is acquired and then reInitializeFactories is called.
+ *
+ * This issues a serviceChanged notification to registered listeners.
+ */
+ virtual void reset(void);
+
+ /**
+ * Return TRUE if the service is in its default state.
+ *
+ * The default implementation returns TRUE if there are no
+ * factories registered.
+ */
+ virtual UBool isDefault(void) const;
+
+ /**
+ * Create a key from an ID. If ID is NULL, returns NULL.
+ *
+ * The default implementation creates an ICUServiceKey instance.
+ * Subclasses can override to define more useful keys appropriate
+ * to the factories they accept.
+ *
+ * @param a pointer to the ID for which to create a default ICUServiceKey.
+ * @param status the error code status.
+ * @return the ICUServiceKey corresponding to ID, or NULL.
+ */
+ virtual ICUServiceKey* createKey(const UnicodeString* id, UErrorCode& status) const;
+
+ /**
+ * Clone object so that caller can own the copy. In ICU2.4, UObject doesn't define
+ * clone, so we need an instance-aware method that knows how to do this.
+ * This is public so factories can call it, but should really be protected.
+ *
+ * @param instance the service instance to clone.
+ * @return a clone of the passed-in instance, or NULL if cloning was unsuccessful.
+ */
+ virtual UObject* cloneInstance(UObject* instance) const = 0;
+
+
+ /************************************************************************
+ * Subclassing API
+ */
+
+ protected:
+
+ /**
+ * Create a factory that wraps a single service object. Called by registerInstance.
+ *
+ * The default implementation returns an instance of SimpleFactory.
+ *
+ * @param instanceToAdopt the service instance to adopt.
+ * @param id the ID to assign to this service instance.
+ * @param visible if TRUE, the ID will be visible.
+ * @param status the error code status.
+ * @return an instance of ICUServiceFactory that maps this instance to the provided ID.
+ */
+ virtual ICUServiceFactory* createSimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status);
+
+ /**
+ * Reinitialize the factory list to its default state. After this call, isDefault()
+ * must return TRUE.
+ *
+ * This issues a serviceChanged notification to registered listeners.
+ *
+ * The default implementation clears the factory list.
+ * Subclasses can override to provide other default initialization
+ * of the factory list. Subclasses must not call this method
+ * directly, since it must only be called while holding write
+ * access to the factory list.
+ */
+ virtual void reInitializeFactories(void);
+
+ /**
+ * Default handler for this service if no factory in the factory list
+ * handled the key passed to getKey.
+ *
+ * The default implementation returns NULL.
+ *
+ * @param key the key.
+ * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or NULL.
+ * @param status the error code status.
+ * @return the service instance, or NULL.
+ */
+ virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const;
+
+ /**
+ * Clear caches maintained by this service.
+ *
+ * Subclasses can override if they implement additional caches
+ * that need to be cleared when the service changes. Subclasses
+ * should generally not call this method directly, as it must only
+ * be called while synchronized on the factory lock.
+ */
+ virtual void clearCaches(void);
+
+ /**
+ * Return true if the listener is accepted.
+ *
+ * The default implementation accepts the listener if it is
+ * a ServiceListener. Subclasses can override this to accept
+ * different listeners.
+ *
+ * @param l the listener to test.
+ * @return TRUE if the service accepts the listener.
+ */
+ virtual UBool acceptsListener(const EventListener& l) const;
+
+ /**
+ * Notify the listener of a service change.
+ *
+ * The default implementation assumes a ServiceListener.
+ * If acceptsListener has been overridden to accept different
+ * listeners, this should be overridden as well.
+ *
+ * @param l the listener to notify.
+ */
+ virtual void notifyListener(EventListener& l) const;
+
+ /************************************************************************
+ * Utilities for subclasses.
+ */
+
+ /**
+ * Clear only the service cache.
+ *
+ * This can be called by subclasses when a change affects the service
+ * cache but not the ID caches, e.g., when the default locale changes
+ * the resolution of IDs also changes, requiring the cache to be
+ * flushed, but not the visible IDs themselves.
+ */
+ void clearServiceCache(void);
+
+ /**
+ * Return a map from visible IDs to factories.
+ * This must only be called when the mutex is held.
+ *
+ * @param status the error code status.
+ * @return a Hashtable containing mappings from visible
+ * IDs to factories.
+ */
+ const Hashtable* getVisibleIDMap(UErrorCode& status) const;
+
+ /**
+ * Allow subclasses to read the time stamp.
+ *
+ * @return the timestamp.
+ */
+ int32_t getTimestamp(void) const;
+
+ /**
+ * Return the number of registered factories.
+ *
+ * @return the number of factories registered at the time of the call.
+ */
+ int32_t countFactories(void) const;
+
+private:
+
+ friend class ::ICUServiceTest; // give tests access to countFactories.
+};
+
+U_NAMESPACE_END
+
+ /* UCONFIG_NO_SERVICE */
+#endif
+
+ /* ICUSERV_H */
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servlk.cpp b/Build/source/libs/icu/icu-xetex/common/servlk.cpp
new file mode 100644
index 00000000000..b6204148458
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servlk.cpp
@@ -0,0 +1,187 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2004, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "unicode/resbund.h"
+#include "uresimp.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ustrfmt.h"
+#include "uhash.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+U_NAMESPACE_BEGIN
+
+LocaleKey*
+LocaleKey::createWithCanonicalFallback(const UnicodeString* primaryID,
+ const UnicodeString* canonicalFallbackID,
+ UErrorCode& status)
+{
+ return LocaleKey::createWithCanonicalFallback(primaryID, canonicalFallbackID, KIND_ANY, status);
+}
+
+LocaleKey*
+LocaleKey::createWithCanonicalFallback(const UnicodeString* primaryID,
+ const UnicodeString* canonicalFallbackID,
+ int32_t kind,
+ UErrorCode& status)
+{
+ if (primaryID == NULL || U_FAILURE(status)) {
+ return NULL;
+ }
+ UnicodeString canonicalPrimaryID;
+ LocaleUtility::canonicalLocaleString(primaryID, canonicalPrimaryID);
+ return new LocaleKey(*primaryID, canonicalPrimaryID, canonicalFallbackID, kind);
+}
+
+LocaleKey::LocaleKey(const UnicodeString& primaryID,
+ const UnicodeString& canonicalPrimaryID,
+ const UnicodeString* canonicalFallbackID,
+ int32_t kind)
+ : ICUServiceKey(primaryID)
+ , _kind(kind)
+ , _primaryID(canonicalPrimaryID)
+ , _fallbackID()
+ , _currentID()
+{
+ _fallbackID.setToBogus();
+ if (_primaryID.length() != 0) {
+ if (canonicalFallbackID != NULL && _primaryID != *canonicalFallbackID) {
+ _fallbackID = *canonicalFallbackID;
+ }
+ }
+
+ _currentID = _primaryID;
+}
+
+LocaleKey::~LocaleKey() {}
+
+UnicodeString&
+LocaleKey::prefix(UnicodeString& result) const {
+ if (_kind != KIND_ANY) {
+ UChar buffer[64];
+ uprv_itou(buffer, 64, _kind, 10, 0);
+ UnicodeString temp(buffer);
+ result.append(temp);
+ }
+ return result;
+}
+
+int32_t
+LocaleKey::kind() const {
+ return _kind;
+}
+
+UnicodeString&
+LocaleKey::canonicalID(UnicodeString& result) const {
+ return result.append(_primaryID);
+}
+
+UnicodeString&
+LocaleKey::currentID(UnicodeString& result) const {
+ if (!_currentID.isBogus()) {
+ result.append(_currentID);
+ }
+ return result;
+}
+
+UnicodeString&
+LocaleKey::currentDescriptor(UnicodeString& result) const {
+ if (!_currentID.isBogus()) {
+ prefix(result).append(PREFIX_DELIMITER).append(_currentID);
+ } else {
+ result.setToBogus();
+ }
+ return result;
+}
+
+Locale&
+LocaleKey::canonicalLocale(Locale& result) const {
+ return LocaleUtility::initLocaleFromName(_primaryID, result);
+}
+
+Locale&
+LocaleKey::currentLocale(Locale& result) const {
+ return LocaleUtility::initLocaleFromName(_currentID, result);
+}
+
+UBool
+LocaleKey::fallback() {
+ if (!_currentID.isBogus()) {
+ int x = _currentID.lastIndexOf(UNDERSCORE_CHAR);
+ if (x != -1) {
+ _currentID.remove(x); // truncate current or fallback, whichever we're pointing to
+ return TRUE;
+ }
+
+ if (!_fallbackID.isBogus()) {
+ _currentID = _fallbackID;
+ _fallbackID.setToBogus();
+ return TRUE;
+ }
+
+ if (_currentID.length() > 0) {
+ _currentID.remove(0); // completely truncate
+ return TRUE;
+ }
+
+ _currentID.setToBogus();
+ }
+
+ return FALSE;
+}
+
+UBool
+LocaleKey::isFallbackOf(const UnicodeString& id) const {
+ UnicodeString temp(id);
+ parseSuffix(temp);
+ return temp.indexOf(_primaryID) == 0 &&
+ (temp.length() == _primaryID.length() ||
+ temp.charAt(_primaryID.length()) == UNDERSCORE_CHAR);
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+LocaleKey::debug(UnicodeString& result) const
+{
+ ICUServiceKey::debug(result);
+ result.append(" kind: ");
+ result.append(_kind);
+ result.append(" primaryID: ");
+ result.append(_primaryID);
+ result.append(" fallbackID: ");
+ result.append(_fallbackID);
+ result.append(" currentID: ");
+ result.append(_currentID);
+ return result;
+}
+
+UnicodeString&
+LocaleKey::debugClass(UnicodeString& result) const
+{
+ return result.append("LocaleKey ");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocaleKey)
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servlkf.cpp b/Build/source/libs/icu/icu-xetex/common/servlkf.cpp
new file mode 100644
index 00000000000..c455080fdd9
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servlkf.cpp
@@ -0,0 +1,151 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2005, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "unicode/resbund.h"
+#include "uresimp.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ustrfmt.h"
+#include "uhash.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+
+U_NAMESPACE_BEGIN
+
+LocaleKeyFactory::LocaleKeyFactory(int32_t coverage)
+ : _name()
+ , _coverage(coverage)
+{
+}
+
+LocaleKeyFactory::LocaleKeyFactory(int32_t coverage, const UnicodeString& name)
+ : _name(name)
+ , _coverage(coverage)
+{
+}
+
+LocaleKeyFactory::~LocaleKeyFactory() {
+}
+
+UObject*
+LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const {
+ if (handlesKey(key, status)) {
+ const LocaleKey& lkey = (const LocaleKey&)key;
+ int32_t kind = lkey.kind();
+ Locale loc;
+ lkey.currentLocale(loc);
+
+ return handleCreate(loc, kind, service, status);
+ }
+ return NULL;
+}
+
+UBool
+LocaleKeyFactory::handlesKey(const ICUServiceKey& key, UErrorCode& status) const {
+ const Hashtable* supported = getSupportedIDs(status);
+ if (supported) {
+ UnicodeString id;
+ key.currentID(id);
+ return supported->get(id) != NULL;
+ }
+ return FALSE;
+}
+
+void
+LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const {
+ const Hashtable* supported = getSupportedIDs(status);
+ if (supported) {
+ UBool visible = (_coverage & 0x1) == 0;
+
+ const UHashElement* elem = NULL;
+ int32_t pos = 0;
+ while ((elem = supported->nextElement(pos)) != NULL) {
+ const UnicodeString& id = *((const UnicodeString*)elem->key.pointer);
+ if (!visible) {
+ result.remove(id);
+ } else {
+ result.put(id, (void*)this, status); // this is dummy non-void marker used for set semantics
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ }
+ }
+}
+
+UnicodeString&
+LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const {
+ if ((_coverage & 0x1) == 0) {
+ //UErrorCode status = U_ZERO_ERROR;
+ // assume if this is called on us, we support some fallback of this id
+ // if (isSupportedID(id, status)) {
+ Locale loc;
+ LocaleUtility::initLocaleFromName(id, loc);
+ return loc.getDisplayName(locale, result);
+ // }
+ }
+ result.setToBogus();
+ return result;
+}
+
+UObject*
+LocaleKeyFactory::handleCreate(const Locale& /* loc */,
+ int32_t /* kind */,
+ const ICUService* /* service */,
+ UErrorCode& /* status */) const {
+ return NULL;
+}
+
+//UBool
+//LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
+// const Hashtable* ids = getSupportedIDs(status);
+// return ids && ids->get(id);
+//}
+
+const Hashtable*
+LocaleKeyFactory::getSupportedIDs(UErrorCode& /* status */) const {
+ return NULL;
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+LocaleKeyFactory::debug(UnicodeString& result) const
+{
+ debugClass(result);
+ result.append(", name: ");
+ result.append(_name);
+ result.append(", coverage: ");
+ result.append(_coverage);
+ return result;
+}
+
+UnicodeString&
+LocaleKeyFactory::debugClass(UnicodeString& result) const
+{
+ return result.append("LocaleKeyFactory");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocaleKeyFactory)
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servloc.h b/Build/source/libs/icu/icu-xetex/common/servloc.h
new file mode 100644
index 00000000000..d08b09e36ea
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servloc.h
@@ -0,0 +1,550 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2005, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#ifndef ICULSERV_H
+#define ICULSERV_H
+
+#include "unicode/utypes.h"
+
+#if UCONFIG_NO_SERVICE
+
+U_NAMESPACE_BEGIN
+
+/*
+ * Allow the declaration of APIs with pointers to ICUService
+ * even when service is removed from the build.
+ */
+class ICULocaleService;
+
+U_NAMESPACE_END
+
+#else
+
+#include "unicode/unistr.h"
+#include "unicode/locid.h"
+#include "unicode/strenum.h"
+
+#include "hash.h"
+#include "uvector.h"
+
+#include "serv.h"
+#include "locutil.h"
+
+U_NAMESPACE_BEGIN
+
+class ICULocaleService;
+
+class LocaleKey;
+class LocaleKeyFactory;
+class SimpleLocaleKeyFactory;
+class ServiceListener;
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * A subclass of Key that implements a locale fallback mechanism.
+ * The first locale to search for is the locale provided by the
+ * client, and the fallback locale to search for is the current
+ * default locale. If a prefix is present, the currentDescriptor
+ * includes it before the locale proper, separated by "/". This
+ * is the default key instantiated by ICULocaleService.
+ *
+ * Canonicalization adjusts the locale string so that the
+ * section before the first understore is in lower case, and the rest
+ * is in upper case, with no trailing underscores.
+ */
+
+class U_COMMON_API LocaleKey : public ICUServiceKey {
+ private:
+ int32_t _kind;
+ UnicodeString _primaryID;
+ UnicodeString _fallbackID;
+ UnicodeString _currentID;
+
+ public:
+ enum {
+ KIND_ANY = -1
+ };
+
+ /**
+ * Create a LocaleKey with canonical primary and fallback IDs.
+ */
+ static LocaleKey* createWithCanonicalFallback(const UnicodeString* primaryID,
+ const UnicodeString* canonicalFallbackID,
+ UErrorCode& status);
+
+ /**
+ * Create a LocaleKey with canonical primary and fallback IDs.
+ */
+ static LocaleKey* createWithCanonicalFallback(const UnicodeString* primaryID,
+ const UnicodeString* canonicalFallbackID,
+ int32_t kind,
+ UErrorCode& status);
+
+ protected:
+ /**
+ * PrimaryID is the user's requested locale string,
+ * canonicalPrimaryID is this string in canonical form,
+ * fallbackID is the current default locale's string in
+ * canonical form.
+ */
+ LocaleKey(const UnicodeString& primaryID,
+ const UnicodeString& canonicalPrimaryID,
+ const UnicodeString* canonicalFallbackID,
+ int32_t kind);
+
+ public:
+ /**
+ * Append the prefix associated with the kind, or nothing if the kind is KIND_ANY.
+ */
+ virtual UnicodeString& prefix(UnicodeString& result) const;
+
+ /**
+ * Return the kind code associated with this key.
+ */
+ virtual int32_t kind() const;
+
+ /**
+ * Return the canonicalID.
+ */
+ virtual UnicodeString& canonicalID(UnicodeString& result) const;
+
+ /**
+ * Return the currentID.
+ */
+ virtual UnicodeString& currentID(UnicodeString& result) const;
+
+ /**
+ * Return the (canonical) current descriptor, or null if no current id.
+ */
+ virtual UnicodeString& currentDescriptor(UnicodeString& result) const;
+
+ /**
+ * Convenience method to return the locale corresponding to the (canonical) original ID.
+ */
+ virtual Locale& canonicalLocale(Locale& result) const;
+
+ /**
+ * Convenience method to return the locale corresponding to the (canonical) current ID.
+ */
+ virtual Locale& currentLocale(Locale& result) const;
+
+ /**
+ * If the key has a fallback, modify the key and return true,
+ * otherwise return false.
+ *
+ * First falls back through the primary ID, then through
+ * the fallbackID. The final fallback is the empty string,
+ * unless the primary id was the empty string, in which case
+ * there is no fallback.
+ */
+ virtual UBool fallback();
+
+ /**
+ * Return true if a key created from id matches, or would eventually
+ * fallback to match, the canonical ID of this key.
+ */
+ virtual UBool isFallbackOf(const UnicodeString& id) const;
+
+ public:
+ /**
+ * UObject boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Destructor.
+ */
+ virtual ~LocaleKey();
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& result) const;
+ virtual UnicodeString& debugClass(UnicodeString& result) const;
+#endif
+
+};
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * A subclass of ICUServiceFactory that uses LocaleKeys, and is able to
+ * 'cover' more specific locales with more general locales that it
+ * supports.
+ *
+ *
Coverage may be either of the values VISIBLE or INVISIBLE.
+ *
+ *
'Visible' indicates that the specific locale(s) supported by
+ * the factory are registered in getSupportedIDs, 'Invisible'
+ * indicates that they are not.
+ *
+ *
Localization of visible ids is handled
+ * by the handling factory, regardless of kind.
+ */
+class U_COMMON_API LocaleKeyFactory : public ICUServiceFactory {
+protected:
+ const UnicodeString _name;
+ const int32_t _coverage;
+
+public:
+ enum {
+ /**
+ * Coverage value indicating that the factory makes
+ * its locales visible, and does not cover more specific
+ * locales.
+ */
+ VISIBLE = 0,
+
+ /**
+ * Coverage value indicating that the factory does not make
+ * its locales visible, and does not cover more specific
+ * locales.
+ */
+ INVISIBLE = 1
+ };
+
+ /**
+ * Destructor.
+ */
+ virtual ~LocaleKeyFactory();
+
+protected:
+ /**
+ * Constructor used by subclasses.
+ */
+ LocaleKeyFactory(int32_t coverage);
+
+ /**
+ * Constructor used by subclasses.
+ */
+ LocaleKeyFactory(int32_t coverage, const UnicodeString& name);
+
+ /**
+ * Implement superclass abstract method. This checks the currentID of
+ * the key against the supported IDs, and passes the canonicalLocale and
+ * kind off to handleCreate (which subclasses must implement).
+ */
+public:
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
+
+protected:
+ virtual UBool handlesKey(const ICUServiceKey& key, UErrorCode& status) const;
+
+public:
+ /**
+ * Override of superclass method. This adjusts the result based
+ * on the coverage rule for this factory.
+ */
+ virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const;
+
+ /**
+ * Return a localized name for the locale represented by id.
+ */
+ virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
+
+protected:
+ /**
+ * Utility method used by create(ICUServiceKey, ICUService). Subclasses can implement
+ * this instead of create. The default returns NULL.
+ */
+ virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* service, UErrorCode& status) const;
+
+ /**
+ * Return true if this id is one the factory supports (visible or
+ * otherwise).
+ */
+ // virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
+
+ /**
+ * Return the set of ids that this factory supports (visible or
+ * otherwise). This can be called often and might need to be
+ * cached if it is expensive to create.
+ */
+ virtual const Hashtable* getSupportedIDs(UErrorCode& status) const;
+
+public:
+ /**
+ * UObject boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ virtual UClassID getDynamicClassID() const;
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& result) const;
+ virtual UnicodeString& debugClass(UnicodeString& result) const;
+#endif
+
+};
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * A LocaleKeyFactory that just returns a single object for a kind/locale.
+ */
+
+class U_COMMON_API SimpleLocaleKeyFactory : public LocaleKeyFactory {
+ private:
+ UObject* _obj;
+ UnicodeString _id;
+ const int32_t _kind;
+
+ public:
+ SimpleLocaleKeyFactory(UObject* objToAdopt,
+ const UnicodeString& locale,
+ int32_t kind,
+ int32_t coverage);
+
+ SimpleLocaleKeyFactory(UObject* objToAdopt,
+ const Locale& locale,
+ int32_t kind,
+ int32_t coverage);
+
+ /**
+ * Destructor.
+ */
+ virtual ~SimpleLocaleKeyFactory();
+
+ /**
+ * Override of superclass method. Returns the service object if kind/locale match. Service is not used.
+ */
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
+
+ /**
+ * Override of superclass method. This adjusts the result based
+ * on the coverage rule for this factory.
+ */
+ virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const;
+
+ protected:
+ /**
+ * Return true if this id is equal to the locale name.
+ */
+ //virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
+
+
+public:
+ /**
+ * UObject boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ virtual UClassID getDynamicClassID() const;
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& result) const;
+ virtual UnicodeString& debugClass(UnicodeString& result) const;
+#endif
+
+};
+
+/*
+ ******************************************************************
+ */
+
+/**
+ * A LocaleKeyFactory that creates a service based on the ICU locale data.
+ * This is a base class for most ICU factories. Subclasses instantiate it
+ * with a constructor that takes a bundle name, which determines the supported
+ * IDs. Subclasses then override handleCreate to create the actual service
+ * object. The default implementation returns a resource bundle.
+ */
+class U_COMMON_API ICUResourceBundleFactory : public LocaleKeyFactory
+{
+ protected:
+ UnicodeString _bundleName;
+
+ public:
+ /**
+ * Convenience constructor that uses the main ICU bundle name.
+ */
+ ICUResourceBundleFactory();
+
+ /**
+ * A service factory based on ICU resource data in resources with
+ * the given name. This should be a 'path' that can be passed to
+ * ures_openAvailableLocales, such as U_ICUDATA or U_ICUDATA_COLL.
+ * The empty string is equivalent to U_ICUDATA.
+ */
+ ICUResourceBundleFactory(const UnicodeString& bundleName);
+
+ /**
+ * Destructor
+ */
+ virtual ~ICUResourceBundleFactory();
+
+protected:
+ /**
+ * Return the supported IDs. This is the set of all locale names in ICULocaleData.
+ */
+ virtual const Hashtable* getSupportedIDs(UErrorCode& status) const;
+
+ /**
+ * Create the service. The default implementation returns the resource bundle
+ * for the locale, ignoring kind, and service.
+ */
+ virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* service, UErrorCode& status) const;
+
+public:
+ /**
+ * UObject boilerplate.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+ virtual UClassID getDynamicClassID() const;
+
+
+#ifdef SERVICE_DEBUG
+ public:
+ virtual UnicodeString& debug(UnicodeString& result) const;
+ virtual UnicodeString& debugClass(UnicodeString& result) const;
+#endif
+
+};
+
+/*
+ ******************************************************************
+ */
+
+class U_COMMON_API ICULocaleService : public ICUService
+{
+ private:
+ Locale fallbackLocale;
+ UnicodeString fallbackLocaleName;
+ UMTX llock;
+
+ public:
+ /**
+ * Construct an ICULocaleService.
+ */
+ ICULocaleService();
+
+ /**
+ * Construct an ICULocaleService with a name (useful for debugging).
+ */
+ ICULocaleService(const UnicodeString& name);
+
+ /**
+ * Destructor.
+ */
+ virtual ~ICULocaleService();
+
+#if 0
+ // redeclare because of overload resolution rules?
+ // no, causes ambiguities since both UnicodeString and Locale have constructors that take a const char*
+ // need some compiler flag to remove warnings
+ UObject* get(const UnicodeString& descriptor, UErrorCode& status) const {
+ return ICUService::get(descriptor, status);
+ }
+
+ UObject* get(const UnicodeString& descriptor, UnicodeString* actualReturn, UErrorCode& status) const {
+ return ICUService::get(descriptor, actualReturn, status);
+ }
+#endif
+
+ /**
+ * Convenience override for callers using locales. This calls
+ * get(Locale, int, Locale[]) with KIND_ANY for kind and null for
+ * actualReturn.
+ */
+ UObject* get(const Locale& locale, UErrorCode& status) const;
+
+ /**
+ * Convenience override for callers using locales. This calls
+ * get(Locale, int, Locale[]) with a null actualReturn.
+ */
+ UObject* get(const Locale& locale, int32_t kind, UErrorCode& status) const;
+
+ /**
+ * Convenience override for callers using locales. This calls
+ * get(Locale, String, Locale[]) with a null kind.
+ */
+ UObject* get(const Locale& locale, Locale* actualReturn, UErrorCode& status) const;
+
+ /**
+ * Convenience override for callers using locales. This uses
+ * createKey(Locale.toString(), kind) to create a key, calls getKey, and then
+ * if actualReturn is not null, returns the actualResult from
+ * getKey (stripping any prefix) into a Locale.
+ */
+ UObject* get(const Locale& locale, int32_t kind, Locale* actualReturn, UErrorCode& status) const;
+
+ /**
+ * Convenience override for callers using locales. This calls
+ * registerObject(Object, Locale, int32_t kind, int coverage)
+ * passing KIND_ANY for the kind, and VISIBLE for the coverage.
+ */
+ virtual URegistryKey registerInstance(UObject* objToAdopt, const Locale& locale, UErrorCode& status);
+
+ /**
+ * Convenience function for callers using locales. This calls
+ * registerObject(Object, Locale, int kind, int coverage)
+ * passing VISIBLE for the coverage.
+ */
+ virtual URegistryKey registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, UErrorCode& status);
+
+ /**
+ * Convenience function for callers using locales. This instantiates
+ * a SimpleLocaleKeyFactory, and registers the factory.
+ */
+ virtual URegistryKey registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status);
+
+
+ /**
+ * (Stop compiler from complaining about hidden overrides.)
+ * Since both UnicodeString and Locale have constructors that take const char*, adding a public
+ * method that takes UnicodeString causes ambiguity at call sites that use const char*.
+ * We really need a flag that is understood by all compilers that will suppress the warning about
+ * hidden overrides.
+ */
+ virtual URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status);
+
+ /**
+ * Convenience method for callers using locales. This returns the standard
+ * service ID enumeration.
+ */
+ virtual StringEnumeration* getAvailableLocales(void) const;
+
+ protected:
+
+ /**
+ * Return the name of the current fallback locale. If it has changed since this was
+ * last accessed, the service cache is cleared.
+ */
+ const UnicodeString& validateFallbackLocale() const;
+
+ /**
+ * Override superclass createKey method.
+ */
+ virtual ICUServiceKey* createKey(const UnicodeString* id, UErrorCode& status) const;
+
+ /**
+ * Additional createKey that takes a kind.
+ */
+ virtual ICUServiceKey* createKey(const UnicodeString* id, int32_t kind, UErrorCode& status) const;
+
+ friend class ServiceEnumeration;
+};
+
+U_NAMESPACE_END
+
+ /* UCONFIG_NO_SERVICE */
+#endif
+
+ /* ICULSERV_H */
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servls.cpp b/Build/source/libs/icu/icu-xetex/common/servls.cpp
new file mode 100644
index 00000000000..b39e72ed62b
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servls.cpp
@@ -0,0 +1,297 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2004, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "unicode/resbund.h"
+#include "uresimp.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ustrfmt.h"
+#include "uhash.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+U_NAMESPACE_BEGIN
+
+ICULocaleService::ICULocaleService()
+ : fallbackLocale(Locale::getDefault())
+ , llock(0)
+{
+ umtx_init(&llock);
+}
+
+ICULocaleService::ICULocaleService(const UnicodeString& dname)
+ : ICUService(dname)
+ , fallbackLocale(Locale::getDefault())
+ , llock(0)
+{
+ umtx_init(&llock);
+}
+
+ICULocaleService::~ICULocaleService()
+{
+ umtx_destroy(&llock);
+}
+
+UObject*
+ICULocaleService::get(const Locale& locale, UErrorCode& status) const
+{
+ return get(locale, LocaleKey::KIND_ANY, NULL, status);
+}
+
+UObject*
+ICULocaleService::get(const Locale& locale, int32_t kind, UErrorCode& status) const
+{
+ return get(locale, kind, NULL, status);
+}
+
+UObject*
+ICULocaleService::get(const Locale& locale, Locale* actualReturn, UErrorCode& status) const
+{
+ return get(locale, LocaleKey::KIND_ANY, actualReturn, status);
+}
+
+UObject*
+ICULocaleService::get(const Locale& locale, int32_t kind, Locale* actualReturn, UErrorCode& status) const
+{
+ UObject* result = NULL;
+ if (U_FAILURE(status)) {
+ return result;
+ }
+
+ UnicodeString locName(locale.getName(), -1, US_INV);
+ if (locName.isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ ICUServiceKey* key = createKey(&locName, kind, status);
+ if (key) {
+ if (actualReturn == NULL) {
+ result = getKey(*key, status);
+ } else {
+ UnicodeString temp;
+ result = getKey(*key, &temp, status);
+
+ if (result != NULL) {
+ key->parseSuffix(temp);
+ LocaleUtility::initLocaleFromName(temp, *actualReturn);
+ }
+ }
+ delete key;
+ }
+ }
+ return result;
+}
+
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale,
+ UBool visible, UErrorCode& status)
+{
+ Locale loc;
+ LocaleUtility::initLocaleFromName(locale, loc);
+ return registerInstance(objToAdopt, loc, LocaleKey::KIND_ANY,
+ visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE, status);
+}
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, UErrorCode& status)
+{
+ return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status);
+}
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, UErrorCode& status)
+{
+ return registerInstance(objToAdopt, locale, kind, LocaleKeyFactory::VISIBLE, status);
+}
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status)
+{
+ ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage);
+ if (factory != NULL) {
+ return registerFactory(factory, status);
+ }
+ delete objToAdopt;
+ return NULL;
+}
+
+#if 0
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UErrorCode& status)
+{
+ return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status);
+}
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status)
+{
+ return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY,
+ visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE,
+ status);
+}
+
+URegistryKey
+ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, int32_t kind, int32_t coverage, UErrorCode& status)
+{
+ ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage);
+ if (factory != NULL) {
+ return registerFactory(factory, status);
+ }
+ delete objToAdopt;
+ return NULL;
+}
+#endif
+
+class ServiceEnumeration : public StringEnumeration {
+private:
+ const ICULocaleService* _service;
+ int32_t _timestamp;
+ UVector _ids;
+ int32_t _pos;
+
+private:
+ ServiceEnumeration(const ICULocaleService* service, UErrorCode &status)
+ : _service(service)
+ , _timestamp(service->getTimestamp())
+ , _ids(uhash_deleteUnicodeString, NULL, status)
+ , _pos(0)
+ {
+ _service->getVisibleIDs(_ids, status);
+ }
+
+ ServiceEnumeration(const ServiceEnumeration &other, UErrorCode &status)
+ : _service(other._service)
+ , _timestamp(other._timestamp)
+ , _ids(uhash_deleteUnicodeString, NULL, status)
+ , _pos(0)
+ {
+ if(U_SUCCESS(status)) {
+ int32_t i, length;
+
+ length = other._ids.size();
+ for(i = 0; i < length; ++i) {
+ _ids.addElement(((UnicodeString *)other._ids.elementAt(i))->clone(), status);
+ }
+
+ if(U_SUCCESS(status)) {
+ _pos = other._pos;
+ }
+ }
+ }
+
+public:
+ static ServiceEnumeration* create(const ICULocaleService* service) {
+ UErrorCode status = U_ZERO_ERROR;
+ ServiceEnumeration* result = new ServiceEnumeration(service, status);
+ if (U_SUCCESS(status)) {
+ return result;
+ }
+ delete result;
+ return NULL;
+ }
+
+ virtual ~ServiceEnumeration() {}
+
+ virtual StringEnumeration *clone() const {
+ UErrorCode status = U_ZERO_ERROR;
+ ServiceEnumeration *cl = new ServiceEnumeration(*this, status);
+ if(U_FAILURE(status)) {
+ delete cl;
+ cl = NULL;
+ }
+ return cl;
+ }
+
+ UBool upToDate(UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ if (_timestamp == _service->getTimestamp()) {
+ return TRUE;
+ }
+ status = U_ENUM_OUT_OF_SYNC_ERROR;
+ }
+ return FALSE;
+ }
+
+ virtual int32_t count(UErrorCode& status) const {
+ return upToDate(status) ? _ids.size() : 0;
+ }
+
+ virtual const UnicodeString* snext(UErrorCode& status) {
+ if (upToDate(status) && (_pos < _ids.size())) {
+ return (const UnicodeString*)_ids[_pos++];
+ }
+ return NULL;
+ }
+
+ virtual void reset(UErrorCode& status) {
+ if (status == U_ENUM_OUT_OF_SYNC_ERROR) {
+ status = U_ZERO_ERROR;
+ }
+ if (U_SUCCESS(status)) {
+ _timestamp = _service->getTimestamp();
+ _pos = 0;
+ _service->getVisibleIDs(_ids, status);
+ }
+ }
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ServiceEnumeration)
+
+StringEnumeration*
+ICULocaleService::getAvailableLocales(void) const
+{
+ return ServiceEnumeration::create(this);
+}
+
+const UnicodeString&
+ICULocaleService::validateFallbackLocale() const
+{
+ const Locale& loc = Locale::getDefault();
+ ICULocaleService* ncThis = (ICULocaleService*)this;
+ {
+ Mutex mutex(&ncThis->llock);
+ if (loc != fallbackLocale) {
+ ncThis->fallbackLocale = loc;
+ LocaleUtility::initNameFromLocale(loc, ncThis->fallbackLocaleName);
+ ncThis->clearServiceCache();
+ }
+ }
+ return fallbackLocaleName;
+}
+
+ICUServiceKey*
+ICULocaleService::createKey(const UnicodeString* id, UErrorCode& status) const
+{
+ return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), status);
+}
+
+ICUServiceKey*
+ICULocaleService::createKey(const UnicodeString* id, int32_t kind, UErrorCode& status) const
+{
+ return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), kind, status);
+}
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servnotf.cpp b/Build/source/libs/icu/icu-xetex/common/servnotf.cpp
new file mode 100644
index 00000000000..6adf52ece2e
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servnotf.cpp
@@ -0,0 +1,118 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2006, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "servnotf.h"
+#ifdef NOTIFIER_DEBUG
+#include
+#endif
+
+U_NAMESPACE_BEGIN
+
+EventListener::~EventListener() {}
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener)
+
+ICUNotifier::ICUNotifier(void)
+: notifyLock(0), listeners(NULL)
+{
+ umtx_init(¬ifyLock);
+}
+
+ICUNotifier::~ICUNotifier(void) {
+ {
+ Mutex lmx(¬ifyLock);
+ delete listeners;
+ listeners = NULL;
+ }
+ umtx_destroy(¬ifyLock);
+}
+
+
+void
+ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if (l == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (acceptsListener(*l)) {
+ Mutex lmx(¬ifyLock);
+ if (listeners == NULL) {
+ listeners = new UVector(5, status);
+ } else {
+ for (int i = 0, e = listeners->size(); i < e; ++i) {
+ const EventListener* el = (const EventListener*)(listeners->elementAt(i));
+ if (l == el) {
+ return;
+ }
+ }
+ }
+
+ listeners->addElement((void*)l, status); // cast away const
+ }
+#ifdef NOTIFIER_DEBUG
+ else {
+ fprintf(stderr, "Listener invalid for this notifier.");
+ exit(1);
+ }
+#endif
+ }
+}
+
+void
+ICUNotifier::removeListener(const EventListener *l, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if (l == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ {
+ Mutex lmx(¬ifyLock);
+ if (listeners != NULL) {
+ // identity equality check
+ for (int i = 0, e = listeners->size(); i < e; ++i) {
+ const EventListener* el = (const EventListener*)listeners->elementAt(i);
+ if (l == el) {
+ listeners->removeElementAt(i);
+ if (listeners->size() == 0) {
+ delete listeners;
+ listeners = NULL;
+ }
+ return;
+ }
+ }
+ }
+ }
+ }
+}
+
+void
+ICUNotifier::notifyChanged(void)
+{
+ if (listeners != NULL) {
+ Mutex lmx(¬ifyLock);
+ if (listeners != NULL) {
+ for (int i = 0, e = listeners->size(); i < e; ++i) {
+ EventListener* el = (EventListener*)listeners->elementAt(i);
+ notifyListener(*el);
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+/* UCONFIG_NO_SERVICE */
+#endif
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servnotf.h b/Build/source/libs/icu/icu-xetex/common/servnotf.h
new file mode 100644
index 00000000000..19c2d6908ee
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servnotf.h
@@ -0,0 +1,124 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2004, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+#ifndef ICUNOTIF_H
+#define ICUNOTIF_H
+
+#include "unicode/utypes.h"
+
+#if UCONFIG_NO_SERVICE
+
+U_NAMESPACE_BEGIN
+
+/*
+ * Allow the declaration of APIs with pointers to BreakIterator
+ * even when break iteration is removed from the build.
+ */
+class ICUNotifier;
+
+U_NAMESPACE_END
+
+#else
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+
+#include "mutex.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+class U_COMMON_API EventListener : public UObject {
+public:
+ virtual ~EventListener();
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ virtual UClassID getDynamicClassID() const;
+
+public:
+#ifdef SERVICE_DEBUG
+ virtual UnicodeString& debug(UnicodeString& result) const {
+ return debugClass(result);
+ }
+
+ virtual UnicodeString& debugClass(UnicodeString& result) const {
+ return result.append("Key");
+ }
+#endif
+};
+
+/**
+ * Abstract implementation of a notification facility. Clients add
+ * EventListeners with addListener and remove them with removeListener.
+ * Notifiers call notifyChanged when they wish to notify listeners.
+ * This queues the listener list on the notification thread, which
+ * eventually dequeues the list and calls notifyListener on each
+ * listener in the list.
+ *
+ * Subclasses override acceptsListener and notifyListener
+ * to add type-safe notification. AcceptsListener should return
+ * true if the listener is of the appropriate type; ICUNotifier
+ * itself will ensure the listener is non-null and that the
+ * identical listener is not already registered with the Notifier.
+ * NotifyListener should cast the listener to the appropriate
+ * type and call the appropriate method on the listener.
+ */
+
+class U_COMMON_API ICUNotifier : public UMemory {
+private: UMTX notifyLock;
+private: UVector* listeners;
+
+public:
+ ICUNotifier(void);
+
+ virtual ~ICUNotifier(void);
+
+ /**
+ * Add a listener to be notified when notifyChanged is called.
+ * The listener must not be null. AcceptsListener must return
+ * true for the listener. Attempts to concurrently
+ * register the identical listener more than once will be
+ * silently ignored.
+ */
+ virtual void addListener(const EventListener* l, UErrorCode& status);
+
+ /**
+ * Stop notifying this listener. The listener must
+ * not be null. Attemps to remove a listener that is
+ * not registered will be silently ignored.
+ */
+ virtual void removeListener(const EventListener* l, UErrorCode& status);
+
+ /**
+ * ICU doesn't spawn its own threads. All listeners are notified in
+ * the thread of the caller. Misbehaved listeners can therefore
+ * indefinitely block the calling thread. Callers should beware of
+ * deadlock situations.
+ */
+ virtual void notifyChanged(void);
+
+protected:
+ /**
+ * Subclasses implement this to return TRUE if the listener is
+ * of the appropriate type.
+ */
+ virtual UBool acceptsListener(const EventListener& l) const = 0;
+
+ /**
+ * Subclasses implement this to notify the listener.
+ */
+ virtual void notifyListener(EventListener& l) const = 0;
+};
+
+U_NAMESPACE_END
+
+/* UCONFIG_NO_SERVICE */
+#endif
+
+/* ICUNOTIF_H */
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/servrbf.cpp b/Build/source/libs/icu/icu-xetex/common/servrbf.cpp
new file mode 100644
index 00000000000..3a0227f76af
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servrbf.cpp
@@ -0,0 +1,94 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2005, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "unicode/resbund.h"
+#include "uresimp.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ustrfmt.h"
+#include "uhash.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+U_NAMESPACE_BEGIN
+
+ICUResourceBundleFactory::ICUResourceBundleFactory()
+ : LocaleKeyFactory(VISIBLE)
+ , _bundleName()
+{
+}
+
+ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName)
+ : LocaleKeyFactory(VISIBLE)
+ , _bundleName(bundleName)
+{
+}
+
+ICUResourceBundleFactory::~ICUResourceBundleFactory() {}
+
+const Hashtable*
+ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ return LocaleUtility::getAvailableLocaleNames(_bundleName);
+ }
+ return NULL;
+}
+
+UObject*
+ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ // _bundleName is a package name
+ // and should only contain invariant characters
+ // ??? is it always true that the max length of the bundle name is 19?
+ // who made this change? -- dlf
+ char pkg[20];
+ int32_t length;
+ length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV);
+ if(length>=(int32_t)sizeof(pkg)) {
+ return NULL;
+ }
+ return new ResourceBundle(pkg, loc, status);
+ }
+ return NULL;
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+ICUResourceBundleFactory::debug(UnicodeString& result) const
+{
+ LocaleKeyFactory::debug(result);
+ result.append(", bundle: ");
+ return result.append(_bundleName);
+}
+
+UnicodeString&
+ICUResourceBundleFactory::debugClass(UnicodeString& result) const
+{
+ return result.append("ICUResourceBundleFactory");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory)
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/servslkf.cpp b/Build/source/libs/icu/icu-xetex/common/servslkf.cpp
new file mode 100644
index 00000000000..b8afaaadc1b
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/servslkf.cpp
@@ -0,0 +1,122 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2001-2005, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ *******************************************************************************
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_SERVICE
+
+#include "unicode/resbund.h"
+#include "uresimp.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ustrfmt.h"
+#include "uhash.h"
+#include "charstr.h"
+#include "ucln_cmn.h"
+#include "uassert.h"
+
+#define UNDERSCORE_CHAR ((UChar)0x005f)
+#define AT_SIGN_CHAR ((UChar)64)
+#define PERIOD_CHAR ((UChar)46)
+
+U_NAMESPACE_BEGIN
+
+/*
+ ******************************************************************
+ */
+
+SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
+ const UnicodeString& locale,
+ int32_t kind,
+ int32_t coverage)
+ : LocaleKeyFactory(coverage)
+ , _obj(objToAdopt)
+ , _id(locale)
+ , _kind(kind)
+{
+}
+
+SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
+ const Locale& locale,
+ int32_t kind,
+ int32_t coverage)
+ : LocaleKeyFactory(coverage)
+ , _obj(objToAdopt)
+ , _id()
+ , _kind(kind)
+{
+ LocaleUtility::initNameFromLocale(locale, _id);
+}
+
+SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
+{
+ delete _obj;
+ _obj = NULL;
+}
+
+UObject*
+SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ const LocaleKey& lkey = (const LocaleKey&)key;
+ if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
+ UnicodeString keyID;
+ lkey.currentID(keyID);
+ if (_id == keyID) {
+ return service->cloneInstance(_obj);
+ }
+ }
+ }
+ return NULL;
+}
+
+//UBool
+//SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
+//{
+// return id == _id;
+//}
+
+void
+SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ if (_coverage & 0x1) {
+ result.remove(_id);
+ } else {
+ result.put(_id, (void*)this, status);
+ }
+ }
+}
+
+#ifdef SERVICE_DEBUG
+UnicodeString&
+SimpleLocaleKeyFactory::debug(UnicodeString& result) const
+{
+ LocaleKeyFactory::debug(result);
+ result.append(", id: ");
+ result.append(_id);
+ result.append(", kind: ");
+ result.append(_kind);
+ return result;
+}
+
+UnicodeString&
+SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
+{
+ return result.append("SimpleLocaleKeyFactory");
+}
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory)
+
+U_NAMESPACE_END
+
+/* !UCONFIG_NO_SERVICE */
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/sprpimpl.h b/Build/source/libs/icu/icu-xetex/common/sprpimpl.h
new file mode 100644
index 00000000000..1422cc3acd5
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/sprpimpl.h
@@ -0,0 +1,129 @@
+/*
+ *******************************************************************************
+ *
+ * Copyright (C) 2003-2006, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *
+ *******************************************************************************
+ * file name: sprpimpl.h
+ * encoding: US-ASCII
+ * tab size: 8 (not used)
+ * indentation:4
+ *
+ * created on: 2003feb1
+ * created by: Ram Viswanadha
+ */
+
+#ifndef SPRPIMPL_H
+#define SPRPIMPL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_IDNA
+
+#include "unicode/ustring.h"
+#include "unicode/parseerr.h"
+#include "unicode/usprep.h"
+#include "unicode/udata.h"
+#include "utrie.h"
+#include "udataswp.h"
+#include "ubidi_props.h"
+
+#define _SPREP_DATA_TYPE "spp"
+
+enum UStringPrepType{
+ USPREP_UNASSIGNED = 0x0000 ,
+ USPREP_MAP = 0x0001 ,
+ USPREP_PROHIBITED = 0x0002 ,
+ USPREP_DELETE = 0x0003 ,
+ USPREP_TYPE_LIMIT = 0x0004
+};
+
+typedef enum UStringPrepType UStringPrepType;
+
+#ifdef USPREP_TYPE_NAMES_ARRAY
+static const char* usprepTypeNames[] ={
+ "UNASSIGNED" ,
+ "MAP" ,
+ "PROHIBITED" ,
+ "DELETE",
+ "TYPE_LIMIT"
+};
+#endif
+
+enum{
+ _SPREP_NORMALIZATION_ON = 0x0001,
+ _SPREP_CHECK_BIDI_ON = 0x0002
+};
+
+enum{
+ _SPREP_TYPE_THRESHOLD = 0xFFF0,
+ _SPREP_MAX_INDEX_VALUE = 0x3FBF, /*16139*/
+ _SPREP_MAX_INDEX_TOP_LENGTH = 0x0003
+};
+
+/* indexes[] value names */
+enum {
+ _SPREP_INDEX_TRIE_SIZE = 0, /* number of bytes in StringPrep trie */
+ _SPREP_INDEX_MAPPING_DATA_SIZE = 1, /* The array that contains the mapping */
+ _SPREP_NORM_CORRECTNS_LAST_UNI_VERSION = 2, /* The index of Unicode version of last entry in NormalizationCorrections.txt */
+ _SPREP_ONE_UCHAR_MAPPING_INDEX_START = 3, /* The starting index of 1 UChar mapping index in the mapping data array */
+ _SPREP_TWO_UCHARS_MAPPING_INDEX_START = 4, /* The starting index of 2 UChars mapping index in the mapping data array */
+ _SPREP_THREE_UCHARS_MAPPING_INDEX_START = 5, /* The starting index of 3 UChars mapping index in the mapping data array */
+ _SPREP_FOUR_UCHARS_MAPPING_INDEX_START = 6, /* The starting index of 4 UChars mapping index in the mapping data array */
+ _SPREP_OPTIONS = 7, /* Bit set of options to turn on in the profile */
+ _SPREP_INDEX_TOP=16 /* changing this requires a new formatVersion */
+};
+
+typedef struct UStringPrepKey UStringPrepKey;
+
+
+struct UStringPrepKey{
+ char* name;
+ char* path;
+};
+
+struct UStringPrepProfile{
+ int32_t indexes[_SPREP_INDEX_TOP];
+ UTrie sprepTrie;
+ const uint16_t* mappingData;
+ UDataMemory* sprepData;
+ const UBiDiProps *bdp; /* used only if checkBiDi is set */
+ int32_t refCount;
+ UBool isDataLoaded;
+ UBool doNFKC;
+ UBool checkBiDi;
+};
+
+/**
+ * Helper function for populating the UParseError struct
+ * @internal
+ */
+U_CAPI void U_EXPORT2
+uprv_syntaxError(const UChar* rules,
+ int32_t pos,
+ int32_t rulesLen,
+ UParseError* parseError);
+
+
+/**
+ * Swap StringPrep .spp profile data. See udataswp.h.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+usprep_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+#endif /* #if !UCONFIG_NO_IDNA */
+
+#endif
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/triedict.cpp b/Build/source/libs/icu/icu-xetex/common/triedict.cpp
new file mode 100644
index 00000000000..bb771f12913
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/triedict.cpp
@@ -0,0 +1,1407 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2006-2007, International Business Machines Corporation *
+ * and others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "triedict.h"
+#include "unicode/chariter.h"
+#include "unicode/uchriter.h"
+#include "unicode/strenum.h"
+#include "unicode/uenum.h"
+#include "unicode/udata.h"
+#include "cmemory.h"
+#include "udataswp.h"
+#include "uvector.h"
+#include "uvectr32.h"
+#include "uarrsort.h"
+
+//#define DEBUG_TRIE_DICT 1
+
+#ifdef DEBUG_TRIE_DICT
+#include
+#include
+#include
+#endif
+
+U_NAMESPACE_BEGIN
+
+/*******************************************************************
+ * TrieWordDictionary
+ */
+
+TrieWordDictionary::TrieWordDictionary() {
+}
+
+TrieWordDictionary::~TrieWordDictionary() {
+}
+
+/*******************************************************************
+ * MutableTrieDictionary
+ */
+
+// Node structure for the ternary, uncompressed trie
+struct TernaryNode : public UMemory {
+ UChar ch; // UTF-16 code unit
+ uint16_t flags; // Flag word
+ TernaryNode *low; // Less-than link
+ TernaryNode *equal; // Equal link
+ TernaryNode *high; // Greater-than link
+
+ TernaryNode(UChar uc);
+ ~TernaryNode();
+};
+
+enum MutableTrieNodeFlags {
+ kEndsWord = 0x0001 // This node marks the end of a valid word
+};
+
+inline
+TernaryNode::TernaryNode(UChar uc) {
+ ch = uc;
+ flags = 0;
+ low = NULL;
+ equal = NULL;
+ high = NULL;
+}
+
+// Not inline since it's recursive
+TernaryNode::~TernaryNode() {
+ delete low;
+ delete equal;
+ delete high;
+}
+
+MutableTrieDictionary::MutableTrieDictionary( UChar median, UErrorCode &status ) {
+ // Start the trie off with something. Having the root node already present
+ // cuts a special case out of the search/insertion functions.
+ // Making it a median character cuts the worse case for searches from
+ // 4x a balanced trie to 2x a balanced trie. It's best to choose something
+ // that starts a word that is midway in the list.
+ fTrie = new TernaryNode(median);
+ if (fTrie == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ fIter = utext_openUChars(NULL, NULL, 0, &status);
+ if (U_SUCCESS(status) && fIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+MutableTrieDictionary::MutableTrieDictionary( UErrorCode &status ) {
+ fTrie = NULL;
+ fIter = utext_openUChars(NULL, NULL, 0, &status);
+ if (U_SUCCESS(status) && fIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+MutableTrieDictionary::~MutableTrieDictionary() {
+ delete fTrie;
+ utext_close(fIter);
+}
+
+int32_t
+MutableTrieDictionary::search( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit,
+ TernaryNode *&parent,
+ UBool &pMatched ) const {
+ // TODO: current implementation works in UTF-16 space
+ const TernaryNode *up = NULL;
+ const TernaryNode *p = fTrie;
+ int mycount = 0;
+ pMatched = TRUE;
+ int i;
+
+ UChar uc = utext_current32(text);
+ for (i = 0; i < maxLength && p != NULL; ++i) {
+ while (p != NULL) {
+ if (uc < p->ch) {
+ up = p;
+ p = p->low;
+ }
+ else if (uc == p->ch) {
+ break;
+ }
+ else {
+ up = p;
+ p = p->high;
+ }
+ }
+ if (p == NULL) {
+ pMatched = FALSE;
+ break;
+ }
+ // Must be equal to get here
+ if (limit > 0 && (p->flags & kEndsWord)) {
+ lengths[mycount++] = i+1;
+ --limit;
+ }
+ up = p;
+ p = p->equal;
+ uc = utext_next32(text);
+ uc = utext_current32(text);
+ }
+
+ // Note that there is no way to reach here with up == 0 unless
+ // maxLength is 0 coming in.
+ parent = (TernaryNode *)up;
+ count = mycount;
+ return i;
+}
+
+void
+MutableTrieDictionary::addWord( const UChar *word,
+ int32_t length,
+ UErrorCode &status ) {
+#if 0
+ if (length <= 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+#endif
+ TernaryNode *parent;
+ UBool pMatched;
+ int count;
+ fIter = utext_openUChars(fIter, word, length, &status);
+
+ int matched;
+ matched = search(fIter, length, NULL, count, 0, parent, pMatched);
+
+ while (matched++ < length) {
+ UChar32 uc = utext_next32(fIter); // TODO: supplemetary support?
+ U_ASSERT(uc != U_SENTINEL);
+ TernaryNode *newNode = new TernaryNode(uc);
+ if (newNode == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (pMatched) {
+ parent->equal = newNode;
+ }
+ else {
+ pMatched = TRUE;
+ if (uc < parent->ch) {
+ parent->low = newNode;
+ }
+ else {
+ parent->high = newNode;
+ }
+ }
+ parent = newNode;
+ }
+
+ parent->flags |= kEndsWord;
+}
+
+#if 0
+void
+MutableTrieDictionary::addWords( UEnumeration *words,
+ UErrorCode &status ) {
+ int32_t length;
+ const UChar *word;
+ while ((word = uenum_unext(words, &length, &status)) && U_SUCCESS(status)) {
+ addWord(word, length, status);
+ }
+}
+#endif
+
+int32_t
+MutableTrieDictionary::matches( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit ) const {
+ TernaryNode *parent;
+ UBool pMatched;
+ return search(text, maxLength, lengths, count, limit, parent, pMatched);
+}
+
+// Implementation of iteration for MutableTrieDictionary
+class MutableTrieEnumeration : public StringEnumeration {
+private:
+ UStack fNodeStack; // Stack of nodes to process
+ UVector32 fBranchStack; // Stack of which branch we are working on
+ TernaryNode *fRoot; // Root node
+ enum StackBranch {
+ kLessThan,
+ kEqual,
+ kGreaterThan,
+ kDone
+ };
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+public:
+ MutableTrieEnumeration(TernaryNode *root, UErrorCode &status)
+ : fNodeStack(status), fBranchStack(status) {
+ fRoot = root;
+ fNodeStack.push(root, status);
+ fBranchStack.push(kLessThan, status);
+ unistr.remove();
+ }
+
+ virtual ~MutableTrieEnumeration() {
+ }
+
+ virtual StringEnumeration *clone() const {
+ UErrorCode status = U_ZERO_ERROR;
+ return new MutableTrieEnumeration(fRoot, status);
+ }
+
+ virtual const UnicodeString *snext(UErrorCode &status) {
+ if (fNodeStack.empty() || U_FAILURE(status)) {
+ return NULL;
+ }
+ TernaryNode *node = (TernaryNode *) fNodeStack.peek();
+ StackBranch where = (StackBranch) fBranchStack.peeki();
+ while (!fNodeStack.empty() && U_SUCCESS(status)) {
+ UBool emit;
+ UBool equal;
+
+ switch (where) {
+ case kLessThan:
+ if (node->low != NULL) {
+ fBranchStack.setElementAt(kEqual, fBranchStack.size()-1);
+ node = (TernaryNode *) fNodeStack.push(node->low, status);
+ where = (StackBranch) fBranchStack.push(kLessThan, status);
+ break;
+ }
+ case kEqual:
+ emit = (node->flags & kEndsWord) != 0;
+ equal = (node->equal != NULL);
+ // If this node should be part of the next emitted string, append
+ // the UChar to the string, and make sure we pop it when we come
+ // back to this node. The character should only be in the string
+ // for as long as we're traversing the equal subtree of this node
+ if (equal || emit) {
+ unistr.append(node->ch);
+ fBranchStack.setElementAt(kGreaterThan, fBranchStack.size()-1);
+ }
+ if (equal) {
+ node = (TernaryNode *) fNodeStack.push(node->equal, status);
+ where = (StackBranch) fBranchStack.push(kLessThan, status);
+ }
+ if (emit) {
+ return &unistr;
+ }
+ if (equal) {
+ break;
+ }
+ case kGreaterThan:
+ // If this node's character is in the string, remove it.
+ if (node->equal != NULL || (node->flags & kEndsWord)) {
+ unistr.truncate(unistr.length()-1);
+ }
+ if (node->high != NULL) {
+ fBranchStack.setElementAt(kDone, fBranchStack.size()-1);
+ node = (TernaryNode *) fNodeStack.push(node->high, status);
+ where = (StackBranch) fBranchStack.push(kLessThan, status);
+ break;
+ }
+ case kDone:
+ fNodeStack.pop();
+ fBranchStack.popi();
+ node = (TernaryNode *) fNodeStack.peek();
+ where = (StackBranch) fBranchStack.peeki();
+ break;
+ default:
+ return NULL;
+ }
+ }
+ return NULL;
+ }
+
+ // Very expensive, but this should never be used.
+ virtual int32_t count(UErrorCode &status) const {
+ MutableTrieEnumeration counter(fRoot, status);
+ int32_t result = 0;
+ while (counter.snext(status) != NULL && U_SUCCESS(status)) {
+ ++result;
+ }
+ return result;
+ }
+
+ virtual void reset(UErrorCode &status) {
+ fNodeStack.removeAllElements();
+ fBranchStack.removeAllElements();
+ fNodeStack.push(fRoot, status);
+ fBranchStack.push(kLessThan, status);
+ unistr.remove();
+ }
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MutableTrieEnumeration)
+
+StringEnumeration *
+MutableTrieDictionary::openWords( UErrorCode &status ) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return new MutableTrieEnumeration(fTrie, status);
+}
+
+/*******************************************************************
+ * CompactTrieDictionary
+ */
+
+struct CompactTrieHeader {
+ uint32_t size; // Size of the data in bytes
+ uint32_t magic; // Magic number (including version)
+ uint16_t nodeCount; // Number of entries in offsets[]
+ uint16_t root; // Node number of the root node
+ uint32_t offsets[1]; // Offsets to nodes from start of data
+};
+
+// Note that to avoid platform-specific alignment issues, all members of the node
+// structures should be the same size, or should contain explicit padding to
+// natural alignment boundaries.
+
+// We can't use a bitfield for the flags+count field, because the layout of those
+// is not portable. 12 bits of count allows for up to 4096 entries in a node.
+struct CompactTrieNode {
+ uint16_t flagscount; // Count of sub-entries, plus flags
+};
+
+enum CompactTrieNodeFlags {
+ kVerticalNode = 0x1000, // This is a vertical node
+ kParentEndsWord = 0x2000, // The node whose equal link points to this ends a word
+ kReservedFlag1 = 0x4000,
+ kReservedFlag2 = 0x8000,
+ kCountMask = 0x0FFF, // The count portion of flagscount
+ kFlagMask = 0xF000 // The flags portion of flagscount
+};
+
+// The two node types are distinguished by the kVerticalNode flag.
+
+struct CompactTrieHorizontalEntry {
+ uint16_t ch; // UChar
+ uint16_t equal; // Equal link node index
+};
+
+// We don't use inheritance here because C++ does not guarantee that the
+// base class comes first in memory!!
+
+struct CompactTrieHorizontalNode {
+ uint16_t flagscount; // Count of sub-entries, plus flags
+ CompactTrieHorizontalEntry entries[1];
+};
+
+struct CompactTrieVerticalNode {
+ uint16_t flagscount; // Count of sub-entries, plus flags
+ uint16_t equal; // Equal link node index
+ uint16_t chars[1]; // Code units
+};
+
+// {'Dic', 1}, version 1
+#define COMPACT_TRIE_MAGIC_1 0x44696301
+
+CompactTrieDictionary::CompactTrieDictionary(UDataMemory *dataObj,
+ UErrorCode &status )
+: fUData(dataObj)
+{
+ fData = (const CompactTrieHeader *) udata_getMemory(dataObj);
+ fOwnData = FALSE;
+ if (fData->magic != COMPACT_TRIE_MAGIC_1) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ fData = NULL;
+ }
+}
+CompactTrieDictionary::CompactTrieDictionary( const void *data,
+ UErrorCode &status )
+: fUData(NULL)
+{
+ fData = (const CompactTrieHeader *) data;
+ fOwnData = FALSE;
+ if (fData->magic != COMPACT_TRIE_MAGIC_1) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ fData = NULL;
+ }
+}
+
+CompactTrieDictionary::CompactTrieDictionary( const MutableTrieDictionary &dict,
+ UErrorCode &status )
+: fUData(NULL)
+{
+ fData = compactMutableTrieDictionary(dict, status);
+ fOwnData = !U_FAILURE(status);
+}
+
+CompactTrieDictionary::~CompactTrieDictionary() {
+ if (fOwnData) {
+ uprv_free((void *)fData);
+ }
+ if (fUData) {
+ udata_close(fUData);
+ }
+}
+
+uint32_t
+CompactTrieDictionary::dataSize() const {
+ return fData->size;
+}
+
+const void *
+CompactTrieDictionary::data() const {
+ return fData;
+}
+
+// This function finds the address of a node for us, given its node ID
+static inline const CompactTrieNode *
+getCompactNode(const CompactTrieHeader *header, uint16_t node) {
+ return (const CompactTrieNode *)((const uint8_t *)header + header->offsets[node]);
+}
+
+int32_t
+CompactTrieDictionary::matches( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit ) const {
+ // TODO: current implementation works in UTF-16 space
+ const CompactTrieNode *node = getCompactNode(fData, fData->root);
+ int mycount = 0;
+
+ UChar uc = utext_current32(text);
+ int i = 0;
+
+ while (node != NULL) {
+ // Check if the node we just exited ends a word
+ if (limit > 0 && (node->flagscount & kParentEndsWord)) {
+ lengths[mycount++] = i;
+ --limit;
+ }
+ // Check that we haven't exceeded the maximum number of input characters.
+ // We have to do that here rather than in the while condition so that
+ // we can check for ending a word, above.
+ if (i >= maxLength) {
+ break;
+ }
+
+ int nodeCount = (node->flagscount & kCountMask);
+ if (nodeCount == 0) {
+ // Special terminal node; return now
+ break;
+ }
+ if (node->flagscount & kVerticalNode) {
+ // Vertical node; check all the characters in it
+ const CompactTrieVerticalNode *vnode = (const CompactTrieVerticalNode *)node;
+ for (int j = 0; j < nodeCount && i < maxLength; ++j) {
+ if (uc != vnode->chars[j]) {
+ // We hit a non-equal character; return
+ goto exit;
+ }
+ utext_next32(text);
+ uc = utext_current32(text);
+ ++i;
+ }
+ // To get here we must have come through the whole list successfully;
+ // go on to the next node. Note that a word cannot end in the middle
+ // of a vertical node.
+ node = getCompactNode(fData, vnode->equal);
+ }
+ else {
+ // Horizontal node; do binary search
+ const CompactTrieHorizontalNode *hnode = (const CompactTrieHorizontalNode *)node;
+ int low = 0;
+ int high = nodeCount-1;
+ int middle;
+ node = NULL; // If we don't find a match, we'll fall out of the loop
+ while (high >= low) {
+ middle = (high+low)/2;
+ if (uc == hnode->entries[middle].ch) {
+ // We hit a match; get the next node and next character
+ node = getCompactNode(fData, hnode->entries[middle].equal);
+ utext_next32(text);
+ uc = utext_current32(text);
+ ++i;
+ break;
+ }
+ else if (uc < hnode->entries[middle].ch) {
+ high = middle-1;
+ }
+ else {
+ low = middle+1;
+ }
+ }
+ }
+ }
+exit:
+ count = mycount;
+ return i;
+}
+
+// Implementation of iteration for CompactTrieDictionary
+class CompactTrieEnumeration : public StringEnumeration {
+private:
+ UVector32 fNodeStack; // Stack of nodes to process
+ UVector32 fIndexStack; // Stack of where in node we are
+ const CompactTrieHeader *fHeader; // Trie data
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+public:
+ CompactTrieEnumeration(const CompactTrieHeader *header, UErrorCode &status)
+ : fNodeStack(status), fIndexStack(status) {
+ fHeader = header;
+ fNodeStack.push(header->root, status);
+ fIndexStack.push(0, status);
+ unistr.remove();
+ }
+
+ virtual ~CompactTrieEnumeration() {
+ }
+
+ virtual StringEnumeration *clone() const {
+ UErrorCode status = U_ZERO_ERROR;
+ return new CompactTrieEnumeration(fHeader, status);
+ }
+
+ virtual const UnicodeString * snext(UErrorCode &status);
+
+ // Very expensive, but this should never be used.
+ virtual int32_t count(UErrorCode &status) const {
+ CompactTrieEnumeration counter(fHeader, status);
+ int32_t result = 0;
+ while (counter.snext(status) != NULL && U_SUCCESS(status)) {
+ ++result;
+ }
+ return result;
+ }
+
+ virtual void reset(UErrorCode &status) {
+ fNodeStack.removeAllElements();
+ fIndexStack.removeAllElements();
+ fNodeStack.push(fHeader->root, status);
+ fIndexStack.push(0, status);
+ unistr.remove();
+ }
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CompactTrieEnumeration)
+
+const UnicodeString *
+CompactTrieEnumeration::snext(UErrorCode &status) {
+ if (fNodeStack.empty() || U_FAILURE(status)) {
+ return NULL;
+ }
+ const CompactTrieNode *node = getCompactNode(fHeader, fNodeStack.peeki());
+ int where = fIndexStack.peeki();
+ while (!fNodeStack.empty() && U_SUCCESS(status)) {
+ int nodeCount = (node->flagscount & kCountMask);
+ UBool goingDown = FALSE;
+ if (nodeCount == 0) {
+ // Terminal node; go up immediately
+ fNodeStack.popi();
+ fIndexStack.popi();
+ node = getCompactNode(fHeader, fNodeStack.peeki());
+ where = fIndexStack.peeki();
+ }
+ else if (node->flagscount & kVerticalNode) {
+ // Vertical node
+ const CompactTrieVerticalNode *vnode = (const CompactTrieVerticalNode *)node;
+ if (where == 0) {
+ // Going down
+ unistr.append((const UChar *)vnode->chars, (int32_t) nodeCount);
+ fIndexStack.setElementAt(1, fIndexStack.size()-1);
+ node = getCompactNode(fHeader, fNodeStack.push(vnode->equal, status));
+ where = fIndexStack.push(0, status);
+ goingDown = TRUE;
+ }
+ else {
+ // Going up
+ unistr.truncate(unistr.length()-nodeCount);
+ fNodeStack.popi();
+ fIndexStack.popi();
+ node = getCompactNode(fHeader, fNodeStack.peeki());
+ where = fIndexStack.peeki();
+ }
+ }
+ else {
+ // Horizontal node
+ const CompactTrieHorizontalNode *hnode = (const CompactTrieHorizontalNode *)node;
+ if (where > 0) {
+ // Pop previous char
+ unistr.truncate(unistr.length()-1);
+ }
+ if (where < nodeCount) {
+ // Push on next node
+ unistr.append((UChar)hnode->entries[where].ch);
+ fIndexStack.setElementAt(where+1, fIndexStack.size()-1);
+ node = getCompactNode(fHeader, fNodeStack.push(hnode->entries[where].equal, status));
+ where = fIndexStack.push(0, status);
+ goingDown = TRUE;
+ }
+ else {
+ // Going up
+ fNodeStack.popi();
+ fIndexStack.popi();
+ node = getCompactNode(fHeader, fNodeStack.peeki());
+ where = fIndexStack.peeki();
+ }
+ }
+ // Check if the parent of the node we've just gone down to ends a
+ // word. If so, return it.
+ if (goingDown && (node->flagscount & kParentEndsWord)) {
+ return &unistr;
+ }
+ }
+ return NULL;
+}
+
+StringEnumeration *
+CompactTrieDictionary::openWords( UErrorCode &status ) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return new CompactTrieEnumeration(fData, status);
+}
+
+//
+// Below here is all code related to converting a ternary trie to a compact trie
+// and back again
+//
+
+// Helper classes to construct the compact trie
+class BuildCompactTrieNode: public UMemory {
+ public:
+ UBool fParentEndsWord;
+ UBool fVertical;
+ UBool fHasDuplicate;
+ int32_t fNodeID;
+ UnicodeString fChars;
+
+ public:
+ BuildCompactTrieNode(UBool parentEndsWord, UBool vertical, UStack &nodes, UErrorCode &status) {
+ fParentEndsWord = parentEndsWord;
+ fHasDuplicate = FALSE;
+ fVertical = vertical;
+ fNodeID = nodes.size();
+ nodes.push(this, status);
+ }
+
+ virtual ~BuildCompactTrieNode() {
+ }
+
+ virtual uint32_t size() {
+ return sizeof(uint16_t);
+ }
+
+ virtual void write(uint8_t *bytes, uint32_t &offset, const UVector32 &/*translate*/) {
+ // Write flag/count
+ *((uint16_t *)(bytes+offset)) = (fChars.length() & kCountMask)
+ | (fVertical ? kVerticalNode : 0) | (fParentEndsWord ? kParentEndsWord : 0 );
+ offset += sizeof(uint16_t);
+ }
+};
+
+class BuildCompactTrieHorizontalNode: public BuildCompactTrieNode {
+ public:
+ UStack fLinks;
+
+ public:
+ BuildCompactTrieHorizontalNode(UBool parentEndsWord, UStack &nodes, UErrorCode &status)
+ : BuildCompactTrieNode(parentEndsWord, FALSE, nodes, status), fLinks(status) {
+ }
+
+ virtual ~BuildCompactTrieHorizontalNode() {
+ }
+
+ virtual uint32_t size() {
+ return offsetof(CompactTrieHorizontalNode,entries) +
+ (fChars.length()*sizeof(CompactTrieHorizontalEntry));
+ }
+
+ virtual void write(uint8_t *bytes, uint32_t &offset, const UVector32 &translate) {
+ BuildCompactTrieNode::write(bytes, offset, translate);
+ int32_t count = fChars.length();
+ for (int32_t i = 0; i < count; ++i) {
+ CompactTrieHorizontalEntry *entry = (CompactTrieHorizontalEntry *)(bytes+offset);
+ entry->ch = fChars[i];
+ entry->equal = translate.elementAti(((BuildCompactTrieNode *)fLinks[i])->fNodeID);
+#ifdef DEBUG_TRIE_DICT
+ if (entry->equal == 0) {
+ fprintf(stderr, "ERROR: horizontal link %d, logical node %d maps to physical node zero\n",
+ i, ((BuildCompactTrieNode *)fLinks[i])->fNodeID);
+ }
+#endif
+ offset += sizeof(CompactTrieHorizontalEntry);
+ }
+ }
+
+ void addNode(UChar ch, BuildCompactTrieNode *link, UErrorCode &status) {
+ fChars.append(ch);
+ fLinks.push(link, status);
+ }
+};
+
+class BuildCompactTrieVerticalNode: public BuildCompactTrieNode {
+ public:
+ BuildCompactTrieNode *fEqual;
+
+ public:
+ BuildCompactTrieVerticalNode(UBool parentEndsWord, UStack &nodes, UErrorCode &status)
+ : BuildCompactTrieNode(parentEndsWord, TRUE, nodes, status) {
+ fEqual = NULL;
+ }
+
+ virtual ~BuildCompactTrieVerticalNode() {
+ }
+
+ virtual uint32_t size() {
+ return offsetof(CompactTrieVerticalNode,chars) + (fChars.length()*sizeof(uint16_t));
+ }
+
+ virtual void write(uint8_t *bytes, uint32_t &offset, const UVector32 &translate) {
+ CompactTrieVerticalNode *node = (CompactTrieVerticalNode *)(bytes+offset);
+ BuildCompactTrieNode::write(bytes, offset, translate);
+ node->equal = translate.elementAti(fEqual->fNodeID);
+ offset += sizeof(node->equal);
+#ifdef DEBUG_TRIE_DICT
+ if (node->equal == 0) {
+ fprintf(stderr, "ERROR: vertical link, logical node %d maps to physical node zero\n",
+ fEqual->fNodeID);
+ }
+#endif
+ fChars.extract(0, fChars.length(), (UChar *)node->chars);
+ offset += sizeof(uint16_t)*fChars.length();
+ }
+
+ void addChar(UChar ch) {
+ fChars.append(ch);
+ }
+
+ void setLink(BuildCompactTrieNode *node) {
+ fEqual = node;
+ }
+};
+
+// Forward declaration
+static void walkHorizontal(const TernaryNode *node,
+ BuildCompactTrieHorizontalNode *building,
+ UStack &nodes,
+ UErrorCode &status);
+
+// Convert one node. Uses recursion.
+
+static BuildCompactTrieNode *
+compactOneNode(const TernaryNode *node, UBool parentEndsWord, UStack &nodes, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ BuildCompactTrieNode *result = NULL;
+ UBool horizontal = (node->low != NULL || node->high != NULL);
+ if (horizontal) {
+ BuildCompactTrieHorizontalNode *hResult =
+ new BuildCompactTrieHorizontalNode(parentEndsWord, nodes, status);
+ if (hResult == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_SUCCESS(status)) {
+ walkHorizontal(node, hResult, nodes, status);
+ result = hResult;
+ }
+ }
+ else {
+ BuildCompactTrieVerticalNode *vResult =
+ new BuildCompactTrieVerticalNode(parentEndsWord, nodes, status);
+ if (vResult == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else if (U_SUCCESS(status)) {
+ UBool endsWord = FALSE;
+ // Take up nodes until we end a word, or hit a node with < or > links
+ do {
+ vResult->addChar(node->ch);
+ endsWord = (node->flags & kEndsWord) != 0;
+ node = node->equal;
+ }
+ while(node != NULL && !endsWord && node->low == NULL && node->high == NULL);
+ if (node == NULL) {
+ if (!endsWord) {
+ status = U_ILLEGAL_ARGUMENT_ERROR; // Corrupt input trie
+ }
+ else {
+ vResult->setLink((BuildCompactTrieNode *)nodes[1]);
+ }
+ }
+ else {
+ vResult->setLink(compactOneNode(node, endsWord, nodes, status));
+ }
+ result = vResult;
+ }
+ }
+ return result;
+}
+
+// Walk the set of peers at the same level, to build a horizontal node.
+// Uses recursion.
+
+static void walkHorizontal(const TernaryNode *node,
+ BuildCompactTrieHorizontalNode *building,
+ UStack &nodes,
+ UErrorCode &status) {
+ while (U_SUCCESS(status) && node != NULL) {
+ if (node->low != NULL) {
+ walkHorizontal(node->low, building, nodes, status);
+ }
+ BuildCompactTrieNode *link = NULL;
+ if (node->equal != NULL) {
+ link = compactOneNode(node->equal, (node->flags & kEndsWord) != 0, nodes, status);
+ }
+ else if (node->flags & kEndsWord) {
+ link = (BuildCompactTrieNode *)nodes[1];
+ }
+ if (U_SUCCESS(status) && link != NULL) {
+ building->addNode(node->ch, link, status);
+ }
+ // Tail recurse manually instead of leaving it to the compiler.
+ //if (node->high != NULL) {
+ // walkHorizontal(node->high, building, nodes, status);
+ //}
+ node = node->high;
+ }
+}
+
+U_NAMESPACE_END
+U_NAMESPACE_USE
+U_CDECL_BEGIN
+static int32_t U_CALLCONV
+_sortBuildNodes(const void * /*context*/, const void *voidl, const void *voidr) {
+ BuildCompactTrieNode *left = *(BuildCompactTrieNode **)voidl;
+ BuildCompactTrieNode *right = *(BuildCompactTrieNode **)voidr;
+ // Check for comparing a node to itself, to avoid spurious duplicates
+ if (left == right) {
+ return 0;
+ }
+ // Most significant is type of node. Can never coalesce.
+ if (left->fVertical != right->fVertical) {
+ return left->fVertical - right->fVertical;
+ }
+ // Next, the "parent ends word" flag. If that differs, we cannot coalesce.
+ if (left->fParentEndsWord != right->fParentEndsWord) {
+ return left->fParentEndsWord - right->fParentEndsWord;
+ }
+ // Next, the string. If that differs, we can never coalesce.
+ int32_t result = left->fChars.compare(right->fChars);
+ if (result != 0) {
+ return result;
+ }
+ // We know they're both the same node type, so branch for the two cases.
+ if (left->fVertical) {
+ result = ((BuildCompactTrieVerticalNode *)left)->fEqual->fNodeID
+ - ((BuildCompactTrieVerticalNode *)right)->fEqual->fNodeID;
+ }
+ else {
+ // We need to compare the links vectors. They should be the
+ // same size because the strings were equal.
+ // We compare the node IDs instead of the pointers, to handle
+ // coalesced nodes.
+ BuildCompactTrieHorizontalNode *hleft, *hright;
+ hleft = (BuildCompactTrieHorizontalNode *)left;
+ hright = (BuildCompactTrieHorizontalNode *)right;
+ int32_t count = hleft->fLinks.size();
+ for (int32_t i = 0; i < count && result == 0; ++i) {
+ result = ((BuildCompactTrieNode *)(hleft->fLinks[i]))->fNodeID -
+ ((BuildCompactTrieNode *)(hright->fLinks[i]))->fNodeID;
+ }
+ }
+ // If they are equal to each other, mark them (speeds coalescing)
+ if (result == 0) {
+ left->fHasDuplicate = TRUE;
+ right->fHasDuplicate = TRUE;
+ }
+ return result;
+}
+U_CDECL_END
+U_NAMESPACE_BEGIN
+
+static void coalesceDuplicates(UStack &nodes, UErrorCode &status) {
+ // We sort the array of nodes to place duplicates next to each other
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t size = nodes.size();
+ void **array = (void **)uprv_malloc(sizeof(void *)*size);
+ if (array == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ (void) nodes.toArray(array);
+
+ // Now repeatedly identify duplicates until there are no more
+ int32_t dupes = 0;
+ long passCount = 0;
+#ifdef DEBUG_TRIE_DICT
+ long totalDupes = 0;
+#endif
+ do {
+ BuildCompactTrieNode *node;
+ BuildCompactTrieNode *first = NULL;
+ BuildCompactTrieNode **p;
+ BuildCompactTrieNode **pFirst = NULL;
+ int32_t counter = size - 2;
+ // Sort the array, skipping nodes 0 and 1. Use quicksort for the first
+ // pass for speed. For the second and subsequent passes, we use stable
+ // (insertion) sort for two reasons:
+ // 1. The array is already mostly ordered, so we get better performance.
+ // 2. The way we find one and only one instance of a set of duplicates is to
+ // check that the node ID equals the array index. If we used an unstable
+ // sort for the second or later passes, it's possible that none of the
+ // duplicates would wind up with a node ID equal to its array index.
+ // The sort stability guarantees that, because as we coalesce more and
+ // more groups, the first element of the resultant group will be one of
+ // the first elements of the groups being coalesced.
+ // To use quicksort for the second and subsequent passes, we would have to
+ // find the minimum of the node numbers in a group, and set all the nodes
+ // in the group to that node number.
+ uprv_sortArray(array+2, counter, sizeof(void *), _sortBuildNodes, NULL, (passCount > 0), &status);
+ dupes = 0;
+ for (p = (BuildCompactTrieNode **)array + 2; counter > 0; --counter, ++p) {
+ node = *p;
+ if (node->fHasDuplicate) {
+ if (first == NULL) {
+ first = node;
+ pFirst = p;
+ }
+ else if (_sortBuildNodes(NULL, pFirst, p) != 0) {
+ // Starting a new run of dupes
+ first = node;
+ pFirst = p;
+ }
+ else if (node->fNodeID != first->fNodeID) {
+ // Slave one to the other, note duplicate
+ node->fNodeID = first->fNodeID;
+ dupes += 1;
+ }
+ }
+ else {
+ // This node has no dupes
+ first = NULL;
+ pFirst = NULL;
+ }
+ }
+ passCount += 1;
+#ifdef DEBUG_TRIE_DICT
+ totalDupes += dupes;
+ fprintf(stderr, "Trie node dupe removal, pass %d: %d nodes tagged\n", passCount, dupes);
+#endif
+ }
+ while (dupes > 0);
+#ifdef DEBUG_TRIE_DICT
+ fprintf(stderr, "Trie node dupe removal complete: %d tagged in %d passes\n", totalDupes, passCount);
+#endif
+
+ // We no longer need the temporary array, as the nodes have all been marked appropriately.
+ uprv_free(array);
+}
+
+U_NAMESPACE_END
+U_CDECL_BEGIN
+static void U_CALLCONV _deleteBuildNode(void *obj) {
+ delete (BuildCompactTrieNode *) obj;
+}
+U_CDECL_END
+U_NAMESPACE_BEGIN
+
+CompactTrieHeader *
+CompactTrieDictionary::compactMutableTrieDictionary( const MutableTrieDictionary &dict,
+ UErrorCode &status ) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+#ifdef DEBUG_TRIE_DICT
+ struct tms timing;
+ struct tms previous;
+ (void) ::times(&previous);
+#endif
+ UStack nodes(_deleteBuildNode, NULL, status); // Index of nodes
+
+ // Add node 0, used as the NULL pointer/sentinel.
+ nodes.addElement((int32_t)0, status);
+
+ // Start by creating the special empty node we use to indicate that the parent
+ // terminates a word. This must be node 1, because the builder assumes
+ // that.
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ BuildCompactTrieNode *terminal = new BuildCompactTrieNode(TRUE, FALSE, nodes, status);
+ if (terminal == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+
+ // This call does all the work of building the new trie structure. The root
+ // will be node 2.
+ BuildCompactTrieNode *root = compactOneNode(dict.fTrie, FALSE, nodes, status);
+#ifdef DEBUG_TRIE_DICT
+ (void) ::times(&timing);
+ fprintf(stderr, "Compact trie built, %d nodes, time user %f system %f\n",
+ nodes.size(), (double)(timing.tms_utime-previous.tms_utime)/CLK_TCK,
+ (double)(timing.tms_stime-previous.tms_stime)/CLK_TCK);
+ previous = timing;
+#endif
+
+ // Now coalesce all duplicate nodes.
+ coalesceDuplicates(nodes, status);
+#ifdef DEBUG_TRIE_DICT
+ (void) ::times(&timing);
+ fprintf(stderr, "Duplicates coalesced, time user %f system %f\n",
+ (double)(timing.tms_utime-previous.tms_utime)/CLK_TCK,
+ (double)(timing.tms_stime-previous.tms_stime)/CLK_TCK);
+ previous = timing;
+#endif
+
+ // Next, build the output trie.
+ // First we compute all the sizes and build the node ID translation table.
+ uint32_t totalSize = offsetof(CompactTrieHeader,offsets);
+ int32_t count = nodes.size();
+ int32_t nodeCount = 1; // The sentinel node we already have
+ BuildCompactTrieNode *node;
+ int32_t i;
+ UVector32 translate(count, status); // Should be no growth needed after this
+ translate.push(0, status); // The sentinel node
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ for (i = 1; i < count; ++i) {
+ node = (BuildCompactTrieNode *)nodes[i];
+ if (node->fNodeID == i) {
+ // Only one node out of each duplicate set is used
+ if (i >= translate.size()) {
+ // Logically extend the mapping table
+ translate.setSize(i+1);
+ }
+ translate.setElementAt(nodeCount++, i);
+ totalSize += node->size();
+ }
+ }
+
+ // Check for overflowing 16 bits worth of nodes.
+ if (nodeCount > 0x10000) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ // Add enough room for the offsets.
+ totalSize += nodeCount*sizeof(uint32_t);
+#ifdef DEBUG_TRIE_DICT
+ (void) ::times(&timing);
+ fprintf(stderr, "Sizes/mapping done, time user %f system %f\n",
+ (double)(timing.tms_utime-previous.tms_utime)/CLK_TCK,
+ (double)(timing.tms_stime-previous.tms_stime)/CLK_TCK);
+ previous = timing;
+ fprintf(stderr, "%d nodes, %d unique, %d bytes\n", nodes.size(), nodeCount, totalSize);
+#endif
+ uint8_t *bytes = (uint8_t *)uprv_malloc(totalSize);
+ if (bytes == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ CompactTrieHeader *header = (CompactTrieHeader *)bytes;
+ header->size = totalSize;
+ header->nodeCount = nodeCount;
+ header->offsets[0] = 0; // Sentinel
+ header->root = translate.elementAti(root->fNodeID);
+#ifdef DEBUG_TRIE_DICT
+ if (header->root == 0) {
+ fprintf(stderr, "ERROR: root node %d translate to physical zero\n", root->fNodeID);
+ }
+#endif
+ uint32_t offset = offsetof(CompactTrieHeader,offsets)+(nodeCount*sizeof(uint32_t));
+ nodeCount = 1;
+ // Now write the data
+ for (i = 1; i < count; ++i) {
+ node = (BuildCompactTrieNode *)nodes[i];
+ if (node->fNodeID == i) {
+ header->offsets[nodeCount++] = offset;
+ node->write(bytes, offset, translate);
+ }
+ }
+#ifdef DEBUG_TRIE_DICT
+ (void) ::times(&timing);
+ fprintf(stderr, "Trie built, time user %f system %f\n",
+ (double)(timing.tms_utime-previous.tms_utime)/CLK_TCK,
+ (double)(timing.tms_stime-previous.tms_stime)/CLK_TCK);
+ previous = timing;
+ fprintf(stderr, "Final offset is %d\n", offset);
+
+ // Collect statistics on node types and sizes
+ int hCount = 0;
+ int vCount = 0;
+ size_t hSize = 0;
+ size_t vSize = 0;
+ size_t hItemCount = 0;
+ size_t vItemCount = 0;
+ uint32_t previousOff = offset;
+ for (uint16_t nodeIdx = nodeCount-1; nodeIdx >= 2; --nodeIdx) {
+ const CompactTrieNode *node = getCompactNode(header, nodeIdx);
+ if (node->flagscount & kVerticalNode) {
+ vCount += 1;
+ vItemCount += (node->flagscount & kCountMask);
+ vSize += previousOff-header->offsets[nodeIdx];
+ }
+ else {
+ hCount += 1;
+ hItemCount += (node->flagscount & kCountMask);
+ hSize += previousOff-header->offsets[nodeIdx];
+ }
+ previousOff = header->offsets[nodeIdx];
+ }
+ fprintf(stderr, "Horizontal nodes: %d total, average %f bytes with %f items\n", hCount,
+ (double)hSize/hCount, (double)hItemCount/hCount);
+ fprintf(stderr, "Vertical nodes: %d total, average %f bytes with %f items\n", vCount,
+ (double)vSize/vCount, (double)vItemCount/vCount);
+#endif
+
+ if (U_FAILURE(status)) {
+ uprv_free(bytes);
+ header = NULL;
+ }
+ else {
+ header->magic = COMPACT_TRIE_MAGIC_1;
+ }
+ return header;
+}
+
+// Forward declaration
+static TernaryNode *
+unpackOneNode( const CompactTrieHeader *header, const CompactTrieNode *node, UErrorCode &status );
+
+
+// Convert a horizontal node (or subarray thereof) into a ternary subtrie
+static TernaryNode *
+unpackHorizontalArray( const CompactTrieHeader *header, const CompactTrieHorizontalEntry *array,
+ int low, int high, UErrorCode &status ) {
+ if (U_FAILURE(status) || low > high) {
+ return NULL;
+ }
+ int middle = (low+high)/2;
+ TernaryNode *result = new TernaryNode(array[middle].ch);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ const CompactTrieNode *equal = getCompactNode(header, array[middle].equal);
+ if (equal->flagscount & kParentEndsWord) {
+ result->flags |= kEndsWord;
+ }
+ result->low = unpackHorizontalArray(header, array, low, middle-1, status);
+ result->high = unpackHorizontalArray(header, array, middle+1, high, status);
+ result->equal = unpackOneNode(header, equal, status);
+ return result;
+}
+
+// Convert one compact trie node into a ternary subtrie
+static TernaryNode *
+unpackOneNode( const CompactTrieHeader *header, const CompactTrieNode *node, UErrorCode &status ) {
+ int nodeCount = (node->flagscount & kCountMask);
+ if (nodeCount == 0 || U_FAILURE(status)) {
+ // Failure, or terminal node
+ return NULL;
+ }
+ if (node->flagscount & kVerticalNode) {
+ const CompactTrieVerticalNode *vnode = (const CompactTrieVerticalNode *)node;
+ TernaryNode *head = NULL;
+ TernaryNode *previous = NULL;
+ TernaryNode *latest = NULL;
+ for (int i = 0; i < nodeCount; ++i) {
+ latest = new TernaryNode(vnode->chars[i]);
+ if (latest == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ if (head == NULL) {
+ head = latest;
+ }
+ if (previous != NULL) {
+ previous->equal = latest;
+ }
+ previous = latest;
+ }
+ if (latest != NULL) {
+ const CompactTrieNode *equal = getCompactNode(header, vnode->equal);
+ if (equal->flagscount & kParentEndsWord) {
+ latest->flags |= kEndsWord;
+ }
+ latest->equal = unpackOneNode(header, equal, status);
+ }
+ return head;
+ }
+ else {
+ // Horizontal node
+ const CompactTrieHorizontalNode *hnode = (const CompactTrieHorizontalNode *)node;
+ return unpackHorizontalArray(header, &hnode->entries[0], 0, nodeCount-1, status);
+ }
+}
+
+MutableTrieDictionary *
+CompactTrieDictionary::cloneMutable( UErrorCode &status ) const {
+ MutableTrieDictionary *result = new MutableTrieDictionary( status );
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ TernaryNode *root = unpackOneNode(fData, getCompactNode(fData, fData->root), status);
+ if (U_FAILURE(status)) {
+ delete root; // Clean up
+ delete result;
+ return NULL;
+ }
+ result->fTrie = root;
+ return result;
+}
+
+U_NAMESPACE_END
+
+U_CAPI int32_t U_EXPORT2
+triedict_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData,
+ UErrorCode *status) {
+
+ if (status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+ if(ds==NULL || inData==NULL || length<-1 || (length>0 && outData==NULL)) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ //
+ // Check that the data header is for for dictionary data.
+ // (Header contents are defined in genxxx.cpp)
+ //
+ const UDataInfo *pInfo = (const UDataInfo *)((const uint8_t *)inData+4);
+ if(!( pInfo->dataFormat[0]==0x54 && /* dataFormat="TrDc" */
+ pInfo->dataFormat[1]==0x72 &&
+ pInfo->dataFormat[2]==0x44 &&
+ pInfo->dataFormat[3]==0x63 &&
+ pInfo->formatVersion[0]==1 )) {
+ udata_printError(ds, "triedict_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0]);
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Swap the data header. (This is the generic ICU Data Header, not the
+ // CompactTrieHeader). This swap also conveniently gets us
+ // the size of the ICU d.h., which lets us locate the start
+ // of the RBBI specific data.
+ //
+ int32_t headerSize=udata_swapDataHeader(ds, inData, length, outData, status);
+
+ //
+ // Get the CompactTrieHeader, and check that it appears to be OK.
+ //
+ const uint8_t *inBytes =(const uint8_t *)inData+headerSize;
+ const CompactTrieHeader *header = (const CompactTrieHeader *)inBytes;
+ if (ds->readUInt32(header->magic) != COMPACT_TRIE_MAGIC_1
+ || ds->readUInt32(header->size) < sizeof(CompactTrieHeader))
+ {
+ udata_printError(ds, "triedict_swap(): CompactTrieHeader is invalid.\n");
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Prefight operation? Just return the size
+ //
+ uint32_t totalSize = ds->readUInt32(header->size);
+ int32_t sizeWithUData = (int32_t)totalSize + headerSize;
+ if (length < 0) {
+ return sizeWithUData;
+ }
+
+ //
+ // Check that length passed in is consistent with length from RBBI data header.
+ //
+ if (length < sizeWithUData) {
+ udata_printError(ds, "triedict_swap(): too few bytes (%d after ICU Data header) for trie data.\n",
+ totalSize);
+ *status=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+ //
+ // Swap the Data. Do the data itself first, then the CompactTrieHeader, because
+ // we need to reference the header to locate the data, and an
+ // inplace swap of the header leaves it unusable.
+ //
+ uint8_t *outBytes = (uint8_t *)outData + headerSize;
+ CompactTrieHeader *outputHeader = (CompactTrieHeader *)outBytes;
+
+#if 0
+ //
+ // If not swapping in place, zero out the output buffer before starting.
+ //
+ if (inBytes != outBytes) {
+ uprv_memset(outBytes, 0, totalSize);
+ }
+
+ // We need to loop through all the nodes in the offset table, and swap each one.
+ uint16_t nodeCount = ds->readUInt16(header->nodeCount);
+ // Skip node 0, which should always be 0.
+ for (int i = 1; i < nodeCount; ++i) {
+ uint32_t nodeOff = ds->readUInt32(header->offsets[i]);
+ const CompactTrieNode *inNode = (const CompactTrieNode *)(inBytes + nodeOff);
+ CompactTrieNode *outNode = (CompactTrieNode *)(outBytes + nodeOff);
+ uint16_t flagscount = ds->readUInt16(inNode->flagscount);
+ uint16_t itemCount = flagscount & kCountMask;
+ ds->writeUInt16(&outNode->flagscount, flagscount);
+ if (itemCount > 0) {
+ if (flagscount & kVerticalNode) {
+ ds->swapArray16(ds, inBytes+nodeOff+offsetof(CompactTrieVerticalNode,chars),
+ itemCount*sizeof(uint16_t),
+ outBytes+nodeOff+offsetof(CompactTrieVerticalNode,chars), status);
+ uint16_t equal = ds->readUInt16(inBytes+nodeOff+offsetof(CompactTrieVerticalNode,equal);
+ ds->writeUInt16(outBytes+nodeOff+offsetof(CompactTrieVerticalNode,equal));
+ }
+ else {
+ const CompactTrieHorizontalNode *inHNode = (const CompactTrieHorizontalNode *)inNode;
+ CompactTrieHorizontalNode *outHNode = (CompactTrieHorizontalNode *)outNode;
+ for (int j = 0; j < itemCount; ++j) {
+ uint16_t word = ds->readUInt16(inHNode->entries[j].ch);
+ ds->writeUInt16(&outHNode->entries[j].ch, word);
+ word = ds->readUInt16(inHNode->entries[j].equal);
+ ds->writeUInt16(&outHNode->entries[j].equal, word);
+ }
+ }
+ }
+ }
+#endif
+
+ // All the data in all the nodes consist of 16 bit items. Swap them all at once.
+ uint16_t nodeCount = ds->readUInt16(header->nodeCount);
+ uint32_t nodesOff = offsetof(CompactTrieHeader,offsets)+((uint32_t)nodeCount*sizeof(uint32_t));
+ ds->swapArray16(ds, inBytes+nodesOff, totalSize-nodesOff, outBytes+nodesOff, status);
+
+ // Swap the header
+ ds->writeUInt32(&outputHeader->size, totalSize);
+ uint32_t magic = ds->readUInt32(header->magic);
+ ds->writeUInt32(&outputHeader->magic, magic);
+ ds->writeUInt16(&outputHeader->nodeCount, nodeCount);
+ uint16_t root = ds->readUInt16(header->root);
+ ds->writeUInt16(&outputHeader->root, root);
+ ds->swapArray32(ds, inBytes+offsetof(CompactTrieHeader,offsets),
+ sizeof(uint32_t)*(int32_t)nodeCount,
+ outBytes+offsetof(CompactTrieHeader,offsets), status);
+
+ return sizeWithUData;
+}
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/triedict.h b/Build/source/libs/icu/icu-xetex/common/triedict.h
new file mode 100644
index 00000000000..b8796617690
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/triedict.h
@@ -0,0 +1,346 @@
+/**
+ *******************************************************************************
+ * Copyright (C) 2006, International Business Machines Corporation and others. *
+ * All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef TRIEDICT_H
+#define TRIEDICT_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/utext.h"
+
+struct UEnumeration;
+struct UDataSwapper;
+struct UDataMemory;
+
+ /**
+ * UDataSwapFn function for use in swapping a compact dictionary.
+ *
+ * @param ds Pointer to UDataSwapper containing global data about the
+ * transformation and function pointers for handling primitive
+ * types.
+ * @param inData Pointer to the input data to be transformed or examined.
+ * @param length Length of the data, counting bytes. May be -1 for preflighting.
+ * If length>=0, then transform the data.
+ * If length==-1, then only determine the length of the data.
+ * The length cannot be determined from the data itself for all
+ * types of data (e.g., not for simple arrays of integers).
+ * @param outData Pointer to the output data buffer.
+ * If length>=0 (transformation), then the output buffer must
+ * have a capacity of at least length.
+ * If length==-1, then outData will not be used and can be NULL.
+ * @param pErrorCode ICU UErrorCode parameter, must not be NULL and must
+ * fulfill U_SUCCESS on input.
+ * @return The actual length of the data.
+ *
+ * @see UDataSwapper
+ */
+
+U_CAPI int32_t U_EXPORT2
+triedict_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+U_NAMESPACE_BEGIN
+
+class StringEnumeration;
+struct CompactTrieHeader;
+
+/*******************************************************************
+ * TrieWordDictionary
+ */
+
+/**
+ * TrieWordDictionary is an abstract class that represents a word
+ * dictionary based on a trie. The base protocol is read-only.
+ * Subclasses may allow writing.
+ */
+class U_COMMON_API TrieWordDictionary : public UMemory {
+ public:
+
+ /**
+ * Default constructor.
+ *
+ */
+ TrieWordDictionary();
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~TrieWordDictionary();
+
+ /**
+ * Find dictionary words that match the text.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left after the longest prefix match in the dictionary.
+ * @param start The current position in text.
+ * @param maxLength The maximum number of code units to match.
+ * @param lengths An array that is filled with the lengths of words that matched.
+ * @param count Filled with the number of elements output in lengths.
+ * @param limit The size of the lengths array; this limits the number of words output.
+ * @return The number of characters in text that were matched.
+ */
+ virtual int32_t matches( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit ) const = 0;
+
+ /**
+ * Return a StringEnumeration for iterating all the words in the dictionary.
+ *
+ * @param status A status code recording the success of the call.
+ * @return A StringEnumeration that will iterate through the whole dictionary.
+ * The caller is responsible for closing it. The order is unspecified.
+ */
+ virtual StringEnumeration *openWords( UErrorCode &status ) const = 0;
+
+};
+
+/*******************************************************************
+ * MutableTrieDictionary
+ */
+
+/**
+ * MutableTrieDictionary is a TrieWordDictionary that allows words to be
+ * added.
+ */
+
+struct TernaryNode; // Forwards declaration
+
+class U_COMMON_API MutableTrieDictionary : public TrieWordDictionary {
+ private:
+ /**
+ * The root node of the trie
+ * @internal
+ */
+
+ TernaryNode *fTrie;
+
+ /**
+ * A UText for internal use
+ * @internal
+ */
+
+ UText *fIter;
+
+ friend class CompactTrieDictionary; // For fast conversion
+
+ public:
+
+ /**
+ * Constructor.
+ *
+ * @param median A UChar around which to balance the trie. Ideally, it should
+ * begin at least one word that is near the median of the set in the dictionary
+ * @param status A status code recording the success of the call.
+ */
+ MutableTrieDictionary( UChar median, UErrorCode &status );
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~MutableTrieDictionary();
+
+ /**
+ * Find dictionary words that match the text.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left after the longest prefix match in the dictionary.
+ * @param maxLength The maximum number of code units to match.
+ * @param lengths An array that is filled with the lengths of words that matched.
+ * @param count Filled with the number of elements output in lengths.
+ * @param limit The size of the lengths array; this limits the number of words output.
+ * @return The number of characters in text that were matched.
+ */
+ virtual int32_t matches( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit ) const;
+
+ /**
+ * Return a StringEnumeration for iterating all the words in the dictionary.
+ *
+ * @param status A status code recording the success of the call.
+ * @return A StringEnumeration that will iterate through the whole dictionary.
+ * The caller is responsible for closing it. The order is unspecified.
+ */
+ virtual StringEnumeration *openWords( UErrorCode &status ) const;
+
+ /**
+ * Add one word to the dictionary.
+ *
+ * @param word A UChar buffer containing the word.
+ * @param length The length of the word.
+ * @param status The resultant status
+ */
+ virtual void addWord( const UChar *word,
+ int32_t length,
+ UErrorCode &status);
+
+#if 0
+ /**
+ * Add all strings from a UEnumeration to the dictionary.
+ *
+ * @param words A UEnumeration that will return the desired words.
+ * @param status The resultant status
+ */
+ virtual void addWords( UEnumeration *words, UErrorCode &status );
+#endif
+
+protected:
+ /**
+ * Search the dictionary for matches.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left after the longest prefix match in the dictionary.
+ * @param maxLength The maximum number of code units to match.
+ * @param lengths An array that is filled with the lengths of words that matched.
+ * @param count Filled with the number of elements output in lengths.
+ * @param limit The size of the lengths array; this limits the number of words output.
+ * @param parent The parent of the current node
+ * @param pMatched The returned parent node matched the input
+ * @return The number of characters in text that were matched.
+ */
+ virtual int32_t search( UText *text,
+ int32_t maxLength,
+ int32_t *lengths,
+ int &count,
+ int limit,
+ TernaryNode *&parent,
+ UBool &pMatched ) const;
+
+private:
+ /**
+ * Private constructor. The root node it not allocated.
+ *
+ * @param status A status code recording the success of the call.
+ */
+ MutableTrieDictionary( UErrorCode &status );
+};
+
+/*******************************************************************
+ * CompactTrieDictionary
+ */
+
+/**
+ * CompactTrieDictionary is a TrieWordDictionary that has been compacted
+ * to save space.
+ */
+class U_COMMON_API CompactTrieDictionary : public TrieWordDictionary {
+ private:
+ /**
+ * The root node of the trie
+ */
+
+ const CompactTrieHeader *fData;
+
+ /**
+ * A UBool indicating whether or not we own the fData.
+ */
+
+ UBool fOwnData;
+
+ UDataMemory *fUData;
+ public:
+ /**
+ * Construct a dictionary from a UDataMemory.
+ *
+ * @param data A pointer to a UDataMemory, which is adopted
+ * @param status A status code giving the result of the constructor
+ */
+ CompactTrieDictionary(UDataMemory *dataObj, UErrorCode &status);
+
+ /**
+ * Construct a dictionary from raw saved data.
+ *
+ * @param data A pointer to the raw data, which is still owned by the caller
+ * @param status A status code giving the result of the constructor
+ */
+ CompactTrieDictionary(const void *dataObj, UErrorCode &status);
+
+ /**
+ * Construct a dictionary from a MutableTrieDictionary.
+ *
+ * @param dict The dictionary to use as input.
+ * @param status A status code recording the success of the call.
+ */
+ CompactTrieDictionary( const MutableTrieDictionary &dict, UErrorCode &status );
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~CompactTrieDictionary();
+
+ /**
+ * Find dictionary words that match the text.
+ *
+ * @param text A UText representing the text. The
+ * iterator is left after the longest prefix match in the dictionary.
+ * @param maxLength The maximum number of code units to match.
+ * @param lengths An array that is filled with the lengths of words that matched.
+ * @param count Filled with the number of elements output in lengths.
+ * @param limit The size of the lengths array; this limits the number of words output.
+ * @return The number of characters in text that were matched.
+ */
+ virtual int32_t matches( UText *text,
+ int32_t rangeEnd,
+ int32_t *lengths,
+ int &count,
+ int limit ) const;
+
+ /**
+ * Return a StringEnumeration for iterating all the words in the dictionary.
+ *
+ * @param status A status code recording the success of the call.
+ * @return A StringEnumeration that will iterate through the whole dictionary.
+ * The caller is responsible for closing it. The order is unspecified.
+ */
+ virtual StringEnumeration *openWords( UErrorCode &status ) const;
+
+ /**
+ * Return the size of the compact data.
+ *
+ * @return The size of the dictionary's compact data.
+ */
+ virtual uint32_t dataSize() const;
+
+ /**
+ * Return a void * pointer to the compact data, platform-endian.
+ *
+ * @return The data for the compact dictionary, suitable for passing to the
+ * constructor.
+ */
+ virtual const void *data() const;
+
+ /**
+ * Return a MutableTrieDictionary clone of this dictionary.
+ *
+ * @param status A status code recording the success of the call.
+ * @return A MutableTrieDictionary with the same data as this dictionary
+ */
+ virtual MutableTrieDictionary *cloneMutable( UErrorCode &status ) const;
+
+ private:
+
+ /**
+ * Convert a MutableTrieDictionary into a compact data blob.
+ *
+ * @param dict The dictionary to convert.
+ * @param status A status code recording the success of the call.
+ * @return A single data blob starting with a CompactTrieHeader.
+ */
+ static CompactTrieHeader *compactMutableTrieDictionary( const MutableTrieDictionary &dict,
+ UErrorCode &status );
+
+};
+
+U_NAMESPACE_END
+
+ /* TRIEDICT_H */
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/uarrsort.c b/Build/source/libs/icu/icu-xetex/common/uarrsort.c
new file mode 100644
index 00000000000..8bc967ce161
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/uarrsort.c
@@ -0,0 +1,236 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: uarrsort.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2003aug04
+* created by: Markus W. Scherer
+*
+* Internal function for sorting arrays.
+*/
+
+#include "unicode/utypes.h"
+#include "cmemory.h"
+#include "uarrsort.h"
+
+enum {
+ MIN_QSORT=9, /* from Knuth */
+ STACK_ITEM_SIZE=200
+};
+
+/* UComparator convenience implementations ---------------------------------- */
+
+U_CAPI int32_t U_EXPORT2
+uprv_uint16Comparator(const void *context, const void *left, const void *right) {
+ return (int32_t)*(const uint16_t *)left - (int32_t)*(const uint16_t *)right;
+}
+
+U_CAPI int32_t U_EXPORT2
+uprv_int32Comparator(const void *context, const void *left, const void *right) {
+ return *(const int32_t *)left - *(const int32_t *)right;
+}
+
+U_CAPI int32_t U_EXPORT2
+uprv_uint32Comparator(const void *context, const void *left, const void *right) {
+ uint32_t l=*(const uint32_t *)left, r=*(const uint32_t *)right;
+
+ /* compare directly because (l-r) would overflow the int32_t result */
+ if(lr */ {
+ return 1;
+ }
+}
+
+/* Straight insertion sort from Knuth vol. III, pg. 81 ---------------------- */
+
+static void
+doInsertionSort(char *array, int32_t start, int32_t limit, int32_t itemSize,
+ UComparator *cmp, const void *context, void *pv) {
+ int32_t i, j;
+
+ for(j=start+1; jstart; --i) {
+ if(/* v>=array[i-1] */ cmp(context, pv, array+(i-1)*itemSize)>=0) {
+ break;
+ }
+
+ /* array[i]=array[i-1]; */
+ uprv_memcpy(array+i*itemSize, array+(i-1)*itemSize, itemSize);
+ }
+
+ if(i!=j) {
+ /* array[i]=v; */
+ uprv_memcpy(array+i*itemSize, pv, itemSize);
+ }
+ }
+}
+
+static void
+insertionSort(char *array, int32_t length, int32_t itemSize,
+ UComparator *cmp, const void *context, UErrorCode *pErrorCode) {
+ UAlignedMemory v[STACK_ITEM_SIZE/sizeof(UAlignedMemory)+1];
+ void *pv;
+
+ /* allocate an intermediate item variable (v) */
+ if(itemSize<=STACK_ITEM_SIZE) {
+ pv=v;
+ } else {
+ pv=uprv_malloc(itemSize);
+ if(pv==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ doInsertionSort(array, 0, length, itemSize, cmp, context, pv);
+
+ if(pv!=v) {
+ uprv_free(pv);
+ }
+}
+
+/* QuickSort ---------------------------------------------------------------- */
+
+/*
+ * This implementation is semi-recursive:
+ * It recurses for the smaller sub-array to shorten the recursion depth,
+ * and loops for the larger sub-array.
+ *
+ * Loosely after QuickSort algorithms in
+ * Niklaus Wirth
+ * Algorithmen und Datenstrukturen mit Modula-2
+ * B.G. Teubner Stuttgart
+ * 4. Auflage 1986
+ * ISBN 3-519-02260-5
+ */
+static void
+subQuickSort(char *array, int32_t start, int32_t limit, int32_t itemSize,
+ UComparator *cmp, const void *context,
+ void *px, void *pw) {
+ int32_t left, right;
+
+ /* start and left are inclusive, limit and right are exclusive */
+ do {
+ if((start+MIN_QSORT)>=limit) {
+ doInsertionSort(array, start, limit, itemSize, cmp, context, px);
+ break;
+ }
+
+ left=start;
+ right=limit;
+
+ /* x=array[middle] */
+ uprv_memcpy(px, array+((start+limit)/2)*itemSize, itemSize);
+
+ do {
+ while(/* array[left]0 && array==NULL) || length<0 || itemSize<=0 || cmp==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if(length<=1) {
+ return;
+ } else if(length0 if left>right
+ *
+ * @internal
+ */
+typedef int32_t U_CALLCONV
+UComparator(const void *context, const void *left, const void *right);
+U_CDECL_END
+
+/**
+ * Array sorting function.
+ * Uses a UComparator for comparing array items to each other, and simple
+ * memory copying to move items.
+ *
+ * @param array The array to be sorted.
+ * @param length The number of items in the array.
+ * @param itemSize The size in bytes of each array item.
+ * @param cmp UComparator function used to compare two items each.
+ * @param context Application-specific pointer, passed through to the UComparator.
+ * @param sortStable If true, a stable sorting algorithm must be used.
+ * @param pErrorCode ICU in/out UErrorCode parameter.
+ *
+ * @internal
+ */
+U_CAPI void U_EXPORT2
+uprv_sortArray(void *array, int32_t length, int32_t itemSize,
+ UComparator *cmp, const void *context,
+ UBool sortStable, UErrorCode *pErrorCode);
+
+/**
+ * Convenience UComparator implementation for uint16_t arrays.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+uprv_uint16Comparator(const void *context, const void *left, const void *right);
+
+/**
+ * Convenience UComparator implementation for int32_t arrays.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+uprv_int32Comparator(const void *context, const void *left, const void *right);
+
+/**
+ * Convenience UComparator implementation for uint32_t arrays.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+uprv_uint32Comparator(const void *context, const void *left, const void *right);
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/uassert.h b/Build/source/libs/icu/icu-xetex/common/uassert.h
new file mode 100644
index 00000000000..9b1a14168fb
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/uassert.h
@@ -0,0 +1,32 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2002-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* File uassert.h
+*
+* Contains U_ASSERT macro
+*
+* By default, U_ASSERT just wraps the C library assert macro.
+* By changing the definition here, the assert behavior for ICU can be changed
+* without affecting other non-ICU uses of the C library assert().
+*
+******************************************************************************
+*/
+
+#ifndef U_ASSERT_H
+#define U_ASSERT_H
+/* utypes.h is included to get the proper define for uint8_t */
+#include "unicode/utypes.h"
+#if U_RELEASE
+#define U_ASSERT(exp)
+#else
+#include
+#define U_ASSERT(exp) assert(exp)
+#endif
+#endif
+
+
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidi.c b/Build/source/libs/icu/icu-xetex/common/ubidi.c
new file mode 100644
index 00000000000..edd693a0443
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidi.c
@@ -0,0 +1,2224 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ubidi.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 1999jul27
+* created by: Markus W. Scherer, updated by Matitiahu Allouche
+*/
+
+#include "cmemory.h"
+#include "unicode/utypes.h"
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "unicode/ubidi.h"
+#include "ubidi_props.h"
+#include "ubidiimp.h"
+#include "uassert.h"
+
+/*
+ * General implementation notes:
+ *
+ * Throughout the implementation, there are comments like (W2) that refer to
+ * rules of the BiDi algorithm in its version 5, in this example to the second
+ * rule of the resolution of weak types.
+ *
+ * For handling surrogate pairs, where two UChar's form one "abstract" (or UTF-32)
+ * character according to UTF-16, the second UChar gets the directional property of
+ * the entire character assigned, while the first one gets a BN, a boundary
+ * neutral, type, which is ignored by most of the algorithm according to
+ * rule (X9) and the implementation suggestions of the BiDi algorithm.
+ *
+ * Later, adjustWSLevels() will set the level for each BN to that of the
+ * following character (UChar), which results in surrogate pairs getting the
+ * same level on each of their surrogates.
+ *
+ * In a UTF-8 implementation, the same thing could be done: the last byte of
+ * a multi-byte sequence would get the "real" property, while all previous
+ * bytes of that sequence would get BN.
+ *
+ * It is not possible to assign all those parts of a character the same real
+ * property because this would fail in the resolution of weak types with rules
+ * that look at immediately surrounding types.
+ *
+ * As a related topic, this implementation does not remove Boundary Neutral
+ * types from the input, but ignores them wherever this is relevant.
+ * For example, the loop for the resolution of the weak types reads
+ * types until it finds a non-BN.
+ * Also, explicit embedding codes are neither changed into BN nor removed.
+ * They are only treated the same way real BNs are.
+ * As stated before, adjustWSLevels() takes care of them at the end.
+ * For the purpose of conformance, the levels of all these codes
+ * do not matter.
+ *
+ * Note that this implementation never modifies the dirProps
+ * after the initial setup.
+ *
+ *
+ * In this implementation, the resolution of weak types (Wn),
+ * neutrals (Nn), and the assignment of the resolved level (In)
+ * are all done in one single loop, in resolveImplicitLevels().
+ * Changes of dirProp values are done on the fly, without writing
+ * them back to the dirProps array.
+ *
+ *
+ * This implementation contains code that allows to bypass steps of the
+ * algorithm that are not needed on the specific paragraph
+ * in order to speed up the most common cases considerably,
+ * like text that is entirely LTR, or RTL text without numbers.
+ *
+ * Most of this is done by setting a bit for each directional property
+ * in a flags variable and later checking for whether there are
+ * any LTR characters or any RTL characters, or both, whether
+ * there are any explicit embedding codes, etc.
+ *
+ * If the (Xn) steps are performed, then the flags are re-evaluated,
+ * because they will then not contain the embedding codes any more
+ * and will be adjusted for override codes, so that subsequently
+ * more bypassing may be possible than what the initial flags suggested.
+ *
+ * If the text is not mixed-directional, then the
+ * algorithm steps for the weak type resolution are not performed,
+ * and all levels are set to the paragraph level.
+ *
+ * If there are no explicit embedding codes, then the (Xn) steps
+ * are not performed.
+ *
+ * If embedding levels are supplied as a parameter, then all
+ * explicit embedding codes are ignored, and the (Xn) steps
+ * are not performed.
+ *
+ * White Space types could get the level of the run they belong to,
+ * and are checked with a test of (flags&MASK_EMBEDDING) to
+ * consider if the paragraph direction should be considered in
+ * the flags variable.
+ *
+ * If there are no White Space types in the paragraph, then
+ * (L1) is not necessary in adjustWSLevels().
+ */
+
+/* to avoid some conditional statements, use tiny constant arrays */
+static const Flags flagLR[2]={ DIRPROP_FLAG(L), DIRPROP_FLAG(R) };
+static const Flags flagE[2]={ DIRPROP_FLAG(LRE), DIRPROP_FLAG(RLE) };
+static const Flags flagO[2]={ DIRPROP_FLAG(LRO), DIRPROP_FLAG(RLO) };
+
+#define DIRPROP_FLAG_LR(level) flagLR[(level)&1]
+#define DIRPROP_FLAG_E(level) flagE[(level)&1]
+#define DIRPROP_FLAG_O(level) flagO[(level)&1]
+
+/* UBiDi object management -------------------------------------------------- */
+
+U_CAPI UBiDi * U_EXPORT2
+ubidi_open(void)
+{
+ UErrorCode errorCode=U_ZERO_ERROR;
+ return ubidi_openSized(0, 0, &errorCode);
+}
+
+U_CAPI UBiDi * U_EXPORT2
+ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode) {
+ UBiDi *pBiDi;
+
+ /* check the argument values */
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return NULL;
+ } else if(maxLength<0 || maxRunCount<0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL; /* invalid arguments */
+ }
+
+ /* allocate memory for the object */
+ pBiDi=(UBiDi *)uprv_malloc(sizeof(UBiDi));
+ if(pBiDi==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ /* reset the object, all pointers NULL, all flags FALSE, all sizes 0 */
+ uprv_memset(pBiDi, 0, sizeof(UBiDi));
+
+ /* get BiDi properties */
+ pBiDi->bdp=ubidi_getSingleton(pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ uprv_free(pBiDi);
+ return NULL;
+ }
+
+ /* allocate memory for arrays as requested */
+ if(maxLength>0) {
+ if( !getInitialDirPropsMemory(pBiDi, maxLength) ||
+ !getInitialLevelsMemory(pBiDi, maxLength)
+ ) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ }
+ } else {
+ pBiDi->mayAllocateText=TRUE;
+ }
+
+ if(maxRunCount>0) {
+ if(maxRunCount==1) {
+ /* use simpleRuns[] */
+ pBiDi->runsSize=sizeof(Run);
+ } else if(!getInitialRunsMemory(pBiDi, maxRunCount)) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ }
+ } else {
+ pBiDi->mayAllocateRuns=TRUE;
+ }
+
+ if(U_SUCCESS(*pErrorCode)) {
+ return pBiDi;
+ } else {
+ ubidi_close(pBiDi);
+ return NULL;
+ }
+}
+
+/*
+ * We are allowed to allocate memory if memory==NULL or
+ * mayAllocate==TRUE for each array that we need.
+ * We also try to grow and shrink memory as needed if we
+ * allocate it.
+ *
+ * Assume sizeNeeded>0.
+ * If *pMemory!=NULL, then assume *pSize>0.
+ *
+ * ### this realloc() may unnecessarily copy the old data,
+ * which we know we don't need any more;
+ * is this the best way to do this??
+ */
+U_CFUNC UBool
+ubidi_getMemory(BidiMemoryForAllocation *bidiMem, int32_t *pSize, UBool mayAllocate, int32_t sizeNeeded) {
+ void **pMemory = (void **)bidiMem;
+ /* check for existing memory */
+ if(*pMemory==NULL) {
+ /* we need to allocate memory */
+ if(mayAllocate && (*pMemory=uprv_malloc(sizeNeeded))!=NULL) {
+ *pSize=sizeNeeded;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ /* there is some memory, is it enough or too much? */
+ if(sizeNeeded>*pSize && !mayAllocate) {
+ /* not enough memory, and we must not allocate */
+ return FALSE;
+ } else if(sizeNeeded!=*pSize && mayAllocate) {
+ /* FOOD FOR THOUGHT: in hope to improve performance, we should
+ * try never shrinking memory, only growing it when required.
+ */
+ /* we may try to grow or shrink */
+ void *memory;
+
+ if((memory=uprv_realloc(*pMemory, sizeNeeded))!=NULL) {
+ *pMemory=memory;
+ *pSize=sizeNeeded;
+ return TRUE;
+ } else {
+ /* we failed to grow */
+ return FALSE;
+ }
+ } else {
+ /* we have at least enough memory and must not allocate */
+ return TRUE;
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_close(UBiDi *pBiDi) {
+ if(pBiDi!=NULL) {
+ pBiDi->pParaBiDi=NULL; /* in case one tries to reuse this block */
+ if(pBiDi->dirPropsMemory!=NULL) {
+ uprv_free(pBiDi->dirPropsMemory);
+ }
+ if(pBiDi->levelsMemory!=NULL) {
+ uprv_free(pBiDi->levelsMemory);
+ }
+ if(pBiDi->runsMemory!=NULL) {
+ uprv_free(pBiDi->runsMemory);
+ }
+ if(pBiDi->parasMemory!=NULL) {
+ uprv_free(pBiDi->parasMemory);
+ }
+ if(pBiDi->insertPoints.points!=NULL) {
+ uprv_free(pBiDi->insertPoints.points);
+ }
+
+ uprv_free(pBiDi);
+ }
+}
+
+/* set to approximate "inverse BiDi" ---------------------------------------- */
+
+U_CAPI void U_EXPORT2
+ubidi_setInverse(UBiDi *pBiDi, UBool isInverse) {
+ if(pBiDi!=NULL) {
+ pBiDi->isInverse=isInverse;
+ pBiDi->reorderingMode = isInverse ? UBIDI_REORDER_INVERSE_NUMBERS_AS_L
+ : UBIDI_REORDER_DEFAULT;
+ }
+}
+
+U_CAPI UBool U_EXPORT2
+ubidi_isInverse(UBiDi *pBiDi) {
+ if(pBiDi!=NULL) {
+ return pBiDi->isInverse;
+ } else {
+ return FALSE;
+ }
+}
+
+/* FOOD FOR THOUGHT: currently the reordering modes are a mixture of
+ * algorithm for direct BiDi, algorithm for inverse BiDi and the bizarre
+ * concept of RUNS_ONLY which is a double operation.
+ * It could be advantageous to divide this into 3 concepts:
+ * a) Operation: direct / inverse / RUNS_ONLY
+ * b) Direct algorithm: default / NUMBERS_SPECIAL / GROUP_NUMBERS_WITH_R
+ * c) Inverse algorithm: default / INVERSE_LIKE_DIRECT / NUMBERS_SPECIAL
+ * This would allow combinations not possible today like RUNS_ONLY with
+ * NUMBERS_SPECIAL.
+ * Also allow to set INSERT_MARKS for the direct step of RUNS_ONLY and
+ * REMOVE_CONTROLS for the inverse step.
+ * Not all combinations would be supported, and probably not all do make sense.
+ * This would need to document which ones are supported and what are the
+ * fallbacks for unsupported combinations.
+ */
+U_CAPI void U_EXPORT2
+ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode) {
+ if ((pBiDi!=NULL) && (reorderingMode >= UBIDI_REORDER_DEFAULT)
+ && (reorderingMode < UBIDI_REORDER_COUNT)) {
+ pBiDi->reorderingMode = reorderingMode;
+ pBiDi->isInverse = (UBool)(reorderingMode == UBIDI_REORDER_INVERSE_NUMBERS_AS_L);
+ }
+}
+
+U_CAPI UBiDiReorderingMode U_EXPORT2
+ubidi_getReorderingMode(UBiDi *pBiDi) {
+ if (pBiDi!=NULL) {
+ return pBiDi->reorderingMode;
+ } else {
+ return UBIDI_REORDER_DEFAULT;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions) {
+ if (reorderingOptions & UBIDI_OPTION_REMOVE_CONTROLS) {
+ reorderingOptions&=~UBIDI_OPTION_INSERT_MARKS;
+ }
+ if (pBiDi!=NULL) {
+ pBiDi->reorderingOptions=reorderingOptions;
+ }
+}
+
+U_CAPI uint32_t U_EXPORT2
+ubidi_getReorderingOptions(UBiDi *pBiDi) {
+ if (pBiDi!=NULL) {
+ return pBiDi->reorderingOptions;
+ } else {
+ return 0;
+ }
+}
+
+/* perform (P2)..(P3) ------------------------------------------------------- */
+
+/*
+ * Get the directional properties for the text,
+ * calculate the flags bit-set, and
+ * determine the paragraph level if necessary.
+ */
+static void
+getDirProps(UBiDi *pBiDi) {
+ const UChar *text=pBiDi->text;
+ DirProp *dirProps=pBiDi->dirPropsMemory; /* pBiDi->dirProps is const */
+
+ int32_t i=0, i0, i1, length=pBiDi->originalLength;
+ Flags flags=0; /* collect all directionalities in the text */
+ UChar32 uchar;
+ DirProp dirProp=0, paraDirDefault=0;/* initialize to avoid compiler warnings */
+ UBool isDefaultLevel=IS_DEFAULT_LEVEL(pBiDi->paraLevel);
+ /* for inverse BiDi, the default para level is set to RTL if there is a
+ strong R or AL character at either end of the text */
+ UBool isDefaultLevelInverse=isDefaultLevel && (UBool)
+ (pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
+ pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL);
+ int32_t lastArabicPos=-1;
+ int32_t controlCount=0;
+ UBool removeBiDiControls = (UBool)(pBiDi->reorderingOptions &
+ UBIDI_OPTION_REMOVE_CONTROLS);
+
+ typedef enum {
+ NOT_CONTEXTUAL, /* 0: not contextual paraLevel */
+ LOOKING_FOR_STRONG, /* 1: looking for first strong char */
+ FOUND_STRONG_CHAR /* 2: found first strong char */
+ } State;
+ State state;
+ int32_t paraStart=0; /* index of first char in paragraph */
+ DirProp paraDir; /* == CONTEXT_RTL within paragraphs
+ starting with strong R char */
+ DirProp lastStrongDir=0; /* for default level & inverse BiDi */
+ int32_t lastStrongLTR=0; /* for STREAMING option */
+
+ if(pBiDi->reorderingOptions & UBIDI_OPTION_STREAMING) {
+ pBiDi->length=0;
+ lastStrongLTR=0;
+ }
+ if(isDefaultLevel) {
+ paraDirDefault=pBiDi->paraLevel&1 ? CONTEXT_RTL : 0;
+ paraDir=paraDirDefault;
+ lastStrongDir=paraDirDefault;
+ state=LOOKING_FOR_STRONG;
+ } else {
+ state=NOT_CONTEXTUAL;
+ paraDir=0;
+ }
+ /* count paragraphs and determine the paragraph level (P2..P3) */
+ /*
+ * see comment in ubidi.h:
+ * the DEFAULT_XXX values are designed so that
+ * their bit 0 alone yields the intended default
+ */
+ for( /* i=0 above */ ; ii0) { /* set previous code units' properties to BN */
+ flags|=DIRPROP_FLAG(BN);
+ do {
+ dirProps[--i1]=(DirProp)(BN|paraDir);
+ } while(i1>i0);
+ }
+ if(state==LOOKING_FOR_STRONG) {
+ if(dirProp==L) {
+ state=FOUND_STRONG_CHAR;
+ if(paraDir) {
+ paraDir=0;
+ for(i1=paraStart; i1reorderingOptions & UBIDI_OPTION_STREAMING) {
+ pBiDi->length=i; /* i is index to next character */
+ }
+ if(isDefaultLevelInverse && (lastStrongDir==CONTEXT_RTL) &&(paraDir!=lastStrongDir)) {
+ for( ; paraStartparaCount++;
+ }
+ if(isDefaultLevel) {
+ state=LOOKING_FOR_STRONG;
+ paraStart=i; /* i is index to next character */
+ paraDir=paraDirDefault;
+ lastStrongDir=paraDirDefault;
+ }
+ }
+ }
+ if(removeBiDiControls && IS_BIDI_CONTROL_CHAR(uchar)) {
+ controlCount++;
+ }
+ }
+ if(isDefaultLevelInverse && (lastStrongDir==CONTEXT_RTL) &&(paraDir!=lastStrongDir)) {
+ for(i1=paraStart; i1paraLevel=GET_PARALEVEL(pBiDi, 0);
+ }
+ if(pBiDi->reorderingOptions & UBIDI_OPTION_STREAMING) {
+ if((lastStrongLTR>pBiDi->length) &&
+ (GET_PARALEVEL(pBiDi, lastStrongLTR)==0)) {
+ pBiDi->length = lastStrongLTR;
+ }
+ if(pBiDi->lengthoriginalLength) {
+ pBiDi->paraCount--;
+ }
+ }
+ /* The following line does nothing new for contextual paraLevel, but is
+ needed for absolute paraLevel. */
+ flags|=DIRPROP_FLAG_LR(pBiDi->paraLevel);
+
+ if(pBiDi->orderParagraphsLTR && (flags&DIRPROP_FLAG(B))) {
+ flags|=DIRPROP_FLAG(L);
+ }
+
+ pBiDi->controlCount = controlCount;
+ pBiDi->flags=flags;
+ pBiDi->lastArabicPos=lastArabicPos;
+}
+
+/* perform (X1)..(X9) ------------------------------------------------------- */
+
+/* determine if the text is mixed-directional or single-directional */
+static UBiDiDirection
+directionFromFlags(UBiDi *pBiDi) {
+ Flags flags=pBiDi->flags;
+ /* if the text contains AN and neutrals, then some neutrals may become RTL */
+ if(!(flags&MASK_RTL || ((flags&DIRPROP_FLAG(AN)) && (flags&MASK_POSSIBLE_N)))) {
+ return UBIDI_LTR;
+ } else if(!(flags&MASK_LTR)) {
+ return UBIDI_RTL;
+ } else {
+ return UBIDI_MIXED;
+ }
+}
+
+/*
+ * Resolve the explicit levels as specified by explicit embedding codes.
+ * Recalculate the flags to have them reflect the real properties
+ * after taking the explicit embeddings into account.
+ *
+ * The BiDi algorithm is designed to result in the same behavior whether embedding
+ * levels are externally specified (from "styled text", supposedly the preferred
+ * method) or set by explicit embedding codes (LRx, RLx, PDF) in the plain text.
+ * That is why (X9) instructs to remove all explicit codes (and BN).
+ * However, in a real implementation, this removal of these codes and their index
+ * positions in the plain text is undesirable since it would result in
+ * reallocated, reindexed text.
+ * Instead, this implementation leaves the codes in there and just ignores them
+ * in the subsequent processing.
+ * In order to get the same reordering behavior, positions with a BN or an
+ * explicit embedding code just get the same level assigned as the last "real"
+ * character.
+ *
+ * Some implementations, not this one, then overwrite some of these
+ * directionality properties at "real" same-level-run boundaries by
+ * L or R codes so that the resolution of weak types can be performed on the
+ * entire paragraph at once instead of having to parse it once more and
+ * perform that resolution on same-level-runs.
+ * This limits the scope of the implicit rules in effectively
+ * the same way as the run limits.
+ *
+ * Instead, this implementation does not modify these codes.
+ * On one hand, the paragraph has to be scanned for same-level-runs, but
+ * on the other hand, this saves another loop to reset these codes,
+ * or saves making and modifying a copy of dirProps[].
+ *
+ *
+ * Note that (Pn) and (Xn) changed significantly from version 4 of the BiDi algorithm.
+ *
+ *
+ * Handling the stack of explicit levels (Xn):
+ *
+ * With the BiDi stack of explicit levels,
+ * as pushed with each LRE, RLE, LRO, and RLO and popped with each PDF,
+ * the explicit level must never exceed UBIDI_MAX_EXPLICIT_LEVEL==61.
+ *
+ * In order to have a correct push-pop semantics even in the case of overflows,
+ * there are two overflow counters:
+ * - countOver60 is incremented with each LRx at level 60
+ * - from level 60, one RLx increases the level to 61
+ * - countOver61 is incremented with each LRx and RLx at level 61
+ *
+ * Popping levels with PDF must work in the opposite order so that level 61
+ * is correct at the correct point. Underflows (too many PDFs) must be checked.
+ *
+ * This implementation assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
+ */
+static UBiDiDirection
+resolveExplicitLevels(UBiDi *pBiDi) {
+ const DirProp *dirProps=pBiDi->dirProps;
+ UBiDiLevel *levels=pBiDi->levels;
+ const UChar *text=pBiDi->text;
+
+ int32_t i=0, length=pBiDi->length;
+ Flags flags=pBiDi->flags; /* collect all directionalities in the text */
+ DirProp dirProp;
+ UBiDiLevel level=GET_PARALEVEL(pBiDi, 0);
+
+ UBiDiDirection direction;
+ int32_t paraIndex=0;
+
+ /* determine if the text is mixed-directional or single-directional */
+ direction=directionFromFlags(pBiDi);
+
+ /* we may not need to resolve any explicit levels, but for multiple
+ paragraphs we want to loop on all chars to set the para boundaries */
+ if((direction!=UBIDI_MIXED) && (pBiDi->paraCount==1)) {
+ /* not mixed directionality: levels don't matter - trailingWSStart will be 0 */
+ } else if((pBiDi->paraCount==1) &&
+ (!(flags&MASK_EXPLICIT) ||
+ (pBiDi->reorderingMode > UBIDI_REORDER_LAST_LOGICAL_TO_VISUAL))) {
+ /* mixed, but all characters are at the same embedding level */
+ /* or we are in "inverse BiDi" */
+ /* and we don't have contextual multiple paragraphs with some B char */
+ /* set all levels to the paragraph level */
+ for(i=0; i=UBIDI_MAX_EXPLICIT_LEVEL */
+ uint32_t countOver60=0, countOver61=0; /* count overflows of explicit levels */
+
+ /* recalculate the flags */
+ flags=0;
+
+ for(i=0; i0) {
+ --countOver61;
+ } else if(countOver60>0 && (embeddingLevel&~UBIDI_LEVEL_OVERRIDE)!=UBIDI_MAX_EXPLICIT_LEVEL) {
+ /* handle LRx overflows from level 60 */
+ --countOver60;
+ } else if(stackTop>0) {
+ /* this is the pop operation; it also pops level 61 while countOver60>0 */
+ --stackTop;
+ embeddingLevel=stack[stackTop];
+ /* } else { (underflow) */
+ }
+ flags|=DIRPROP_FLAG(BN);
+ break;
+ case B:
+ stackTop=0;
+ countOver60=countOver61=0;
+ level=GET_PARALEVEL(pBiDi, i);
+ if((i+1)paras[paraIndex++]=i+1;
+ }
+ }
+ flags|=DIRPROP_FLAG(B);
+ break;
+ case BN:
+ /* BN, LRE, RLE, and PDF are supposed to be removed (X9) */
+ /* they will get their levels set correctly in adjustWSLevels() */
+ flags|=DIRPROP_FLAG(BN);
+ break;
+ default:
+ /* all other types get the "real" level */
+ if(level!=embeddingLevel) {
+ level=embeddingLevel;
+ if(level&UBIDI_LEVEL_OVERRIDE) {
+ flags|=DIRPROP_FLAG_O(level)|DIRPROP_FLAG_MULTI_RUNS;
+ } else {
+ flags|=DIRPROP_FLAG_E(level)|DIRPROP_FLAG_MULTI_RUNS;
+ }
+ }
+ if(!(level&UBIDI_LEVEL_OVERRIDE)) {
+ flags|=DIRPROP_FLAG(dirProp);
+ }
+ break;
+ }
+
+ /*
+ * We need to set reasonable levels even on BN codes and
+ * explicit codes because we will later look at same-level runs (X10).
+ */
+ levels[i]=level;
+ }
+ if(flags&MASK_EMBEDDING) {
+ flags|=DIRPROP_FLAG_LR(pBiDi->paraLevel);
+ }
+ if(pBiDi->orderParagraphsLTR && (flags&DIRPROP_FLAG(B))) {
+ flags|=DIRPROP_FLAG(L);
+ }
+
+ /* subsequently, ignore the explicit codes and BN (X9) */
+
+ /* again, determine if the text is mixed-directional or single-directional */
+ pBiDi->flags=flags;
+ direction=directionFromFlags(pBiDi);
+ }
+
+ return direction;
+}
+
+/*
+ * Use a pre-specified embedding levels array:
+ *
+ * Adjust the directional properties for overrides (->LEVEL_OVERRIDE),
+ * ignore all explicit codes (X9),
+ * and check all the preset levels.
+ *
+ * Recalculate the flags to have them reflect the real properties
+ * after taking the explicit embeddings into account.
+ */
+static UBiDiDirection
+checkExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
+ const DirProp *dirProps=pBiDi->dirProps;
+ DirProp dirProp;
+ UBiDiLevel *levels=pBiDi->levels;
+ const UChar *text=pBiDi->text;
+
+ int32_t i, length=pBiDi->length;
+ Flags flags=0; /* collect all directionalities in the text */
+ UBiDiLevel level;
+ uint32_t paraIndex=0;
+
+ for(i=0; iparas[paraIndex++]=i+1;
+ }
+ }
+ }
+ if(flags&MASK_EMBEDDING) {
+ flags|=DIRPROP_FLAG_LR(pBiDi->paraLevel);
+ }
+
+ /* determine if the text is mixed-directional or single-directional */
+ pBiDi->flags=flags;
+ return directionFromFlags(pBiDi);
+}
+
+/******************************************************************
+ The Properties state machine table
+*******************************************************************
+
+ All table cells are 8 bits:
+ bits 0..4: next state
+ bits 5..7: action to perform (if > 0)
+
+ Cells may be of format "n" where n represents the next state
+ (except for the rightmost column).
+ Cells may also be of format "s(x,y)" where x represents an action
+ to perform and y represents the next state.
+
+*******************************************************************
+ Definitions and type for properties state table
+*******************************************************************
+*/
+#define IMPTABPROPS_COLUMNS 14
+#define IMPTABPROPS_RES (IMPTABPROPS_COLUMNS - 1)
+#define GET_STATEPROPS(cell) ((cell)&0x1f)
+#define GET_ACTIONPROPS(cell) ((cell)>>5)
+#define s(action, newState) ((uint8_t)(newState+(action<<5)))
+
+static const uint8_t groupProp[] = /* dirProp regrouped */
+{
+/* L R EN ES ET AN CS B S WS ON LRE LRO AL RLE RLO PDF NSM BN */
+ 0, 1, 2, 7, 8, 3, 9, 6, 5, 4, 4, 10, 10, 12, 10, 10, 10, 11, 10
+};
+
+/* #undef symbols that may have been defined by ctype.h on IRIX or HP-UX */
+#undef _L
+#undef _S
+#undef _B
+
+enum { _L=0, _R=1, _EN=2, _AN=3, _ON=4, _S=5, _B=6 }; /* reduced dirProp */
+
+/******************************************************************
+
+ PROPERTIES STATE TABLE
+
+ In table impTabProps,
+ - the ON column regroups ON and WS
+ - the BN column regroups BN, LRE, RLE, LRO, RLO, PDF
+ - the Res column is the reduced property assigned to a run
+
+ Action 1: process current run1, init new run1
+ 2: init new run2
+ 3: process run1, process run2, init new run1
+ 4: process run1, set run1=run2, init new run2
+
+ Notes:
+ 1) This table is used in resolveImplicitLevels().
+ 2) This table triggers actions when there is a change in the Bidi
+ property of incoming characters (action 1).
+ 3) Most such property sequences are processed immediately (in
+ fact, passed to processPropertySeq().
+ 4) However, numbers are assembled as one sequence. This means
+ that undefined situations (like CS following digits, until
+ it is known if the next char will be a digit) are held until
+ following chars define them.
+ Example: digits followed by CS, then comes another CS or ON;
+ the digits will be processed, then the CS assigned
+ as the start of an ON sequence (action 3).
+ 5) There are cases where more than one sequence must be
+ processed, for instance digits followed by CS followed by L:
+ the digits must be processed as one sequence, and the CS
+ must be processed as an ON sequence, all this before starting
+ assembling chars for the opening L sequence.
+
+
+*/
+static const uint8_t impTabProps[][IMPTABPROPS_COLUMNS] =
+{
+/* L , R , EN , AN , ON , S , B , ES , ET , CS , BN , NSM , AL , Res */
+/* 0 Init */ { 1 , 2 , 4 , 5 , 7 , 15 , 17 , 7 , 9 , 7 , 0 , 7 , 3 , _ON },
+/* 1 L */ { 1 , s(1,2), s(1,4), s(1,5), s(1,7),s(1,15),s(1,17), s(1,7), s(1,9), s(1,7), 1 , 1 , s(1,3), _L },
+/* 2 R */ { s(1,1), 2 , s(1,4), s(1,5), s(1,7),s(1,15),s(1,17), s(1,7), s(1,9), s(1,7), 2 , 2 , s(1,3), _R },
+/* 3 AL */ { s(1,1), s(1,2), s(1,6), s(1,6), s(1,8),s(1,16),s(1,17), s(1,8), s(1,8), s(1,8), 3 , 3 , 3 , _R },
+/* 4 EN */ { s(1,1), s(1,2), 4 , s(1,5), s(1,7),s(1,15),s(1,17),s(2,10), 11 ,s(2,10), 4 , 4 , s(1,3), _EN },
+/* 5 AN */ { s(1,1), s(1,2), s(1,4), 5 , s(1,7),s(1,15),s(1,17), s(1,7), s(1,9),s(2,12), 5 , 5 , s(1,3), _AN },
+/* 6 AL:EN/AN */ { s(1,1), s(1,2), 6 , 6 , s(1,8),s(1,16),s(1,17), s(1,8), s(1,8),s(2,13), 6 , 6 , s(1,3), _AN },
+/* 7 ON */ { s(1,1), s(1,2), s(1,4), s(1,5), 7 ,s(1,15),s(1,17), 7 ,s(2,14), 7 , 7 , 7 , s(1,3), _ON },
+/* 8 AL:ON */ { s(1,1), s(1,2), s(1,6), s(1,6), 8 ,s(1,16),s(1,17), 8 , 8 , 8 , 8 , 8 , s(1,3), _ON },
+/* 9 ET */ { s(1,1), s(1,2), 4 , s(1,5), 7 ,s(1,15),s(1,17), 7 , 9 , 7 , 9 , 9 , s(1,3), _ON },
+/*10 EN+ES/CS */ { s(3,1), s(3,2), 4 , s(3,5), s(4,7),s(3,15),s(3,17), s(4,7),s(4,14), s(4,7), 10 , s(4,7), s(3,3), _EN },
+/*11 EN+ET */ { s(1,1), s(1,2), 4 , s(1,5), s(1,7),s(1,15),s(1,17), s(1,7), 11 , s(1,7), 11 , 11 , s(1,3), _EN },
+/*12 AN+CS */ { s(3,1), s(3,2), s(3,4), 5 , s(4,7),s(3,15),s(3,17), s(4,7),s(4,14), s(4,7), 12 , s(4,7), s(3,3), _AN },
+/*13 AL:EN/AN+CS */ { s(3,1), s(3,2), 6 , 6 , s(4,8),s(3,16),s(3,17), s(4,8), s(4,8), s(4,8), 13 , s(4,8), s(3,3), _AN },
+/*14 ON+ET */ { s(1,1), s(1,2), s(4,4), s(1,5), 7 ,s(1,15),s(1,17), 7 , 14 , 7 , 14 , 14 , s(1,3), _ON },
+/*15 S */ { s(1,1), s(1,2), s(1,4), s(1,5), s(1,7), 15 ,s(1,17), s(1,7), s(1,9), s(1,7), 15 , s(1,7), s(1,3), _S },
+/*16 AL:S */ { s(1,1), s(1,2), s(1,6), s(1,6), s(1,8), 16 ,s(1,17), s(1,8), s(1,8), s(1,8), 16 , s(1,8), s(1,3), _S },
+/*17 B */ { s(1,1), s(1,2), s(1,4), s(1,5), s(1,7),s(1,15), 17 , s(1,7), s(1,9), s(1,7), 17 , s(1,7), s(1,3), _B }
+};
+
+/* we must undef macro s because the levels table have a different
+ * structure (4 bits for action and 4 bits for next state.
+ */
+#undef s
+
+/******************************************************************
+ The levels state machine tables
+*******************************************************************
+
+ All table cells are 8 bits:
+ bits 0..3: next state
+ bits 4..7: action to perform (if > 0)
+
+ Cells may be of format "n" where n represents the next state
+ (except for the rightmost column).
+ Cells may also be of format "s(x,y)" where x represents an action
+ to perform and y represents the next state.
+
+ This format limits each table to 16 states each and to 15 actions.
+
+*******************************************************************
+ Definitions and type for levels state tables
+*******************************************************************
+*/
+#define IMPTABLEVELS_COLUMNS (_B + 2)
+#define IMPTABLEVELS_RES (IMPTABLEVELS_COLUMNS - 1)
+#define GET_STATE(cell) ((cell)&0x0f)
+#define GET_ACTION(cell) ((cell)>>4)
+#define s(action, newState) ((uint8_t)(newState+(action<<4)))
+
+typedef uint8_t ImpTab[][IMPTABLEVELS_COLUMNS];
+typedef uint8_t ImpAct[];
+
+/* FOOD FOR THOUGHT: each ImpTab should have its associated ImpAct,
+ * instead of having a pair of ImpTab and a pair of ImpAct.
+ */
+typedef struct ImpTabPair {
+ const void * pImpTab[2];
+ const void * pImpAct[2];
+} ImpTabPair;
+
+/******************************************************************
+
+ LEVELS STATE TABLES
+
+ In all levels state tables,
+ - state 0 is the initial state
+ - the Res column is the increment to add to the text level
+ for this property sequence.
+
+ The impAct arrays for each table of a pair map the local action
+ numbers of the table to the total list of actions. For instance,
+ action 2 in a given table corresponds to the action number which
+ appears in entry [2] of the impAct array for that table.
+ The first entry of all impAct arrays must be 0.
+
+ Action 1: init conditional sequence
+ 2: prepend conditional sequence to current sequence
+ 3: set ON sequence to new level - 1
+ 4: init EN/AN/ON sequence
+ 5: fix EN/AN/ON sequence followed by R
+ 6: set previous level sequence to level 2
+
+ Notes:
+ 1) These tables are used in processPropertySeq(). The input
+ is property sequences as determined by resolveImplicitLevels.
+ 2) Most such property sequences are processed immediately
+ (levels are assigned).
+ 3) However, some sequences cannot be assigned a final level till
+ one or more following sequences are received. For instance,
+ ON following an R sequence within an even-level paragraph.
+ If the following sequence is R, the ON sequence will be
+ assigned basic run level+1, and so will the R sequence.
+ 4) S is generally handled like ON, since its level will be fixed
+ to paragraph level in adjustWSLevels().
+
+*/
+
+static const ImpTab impTabL_DEFAULT = /* Even paragraph level */
+/* In this table, conditional sequences receive the higher possible level
+ until proven otherwise.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 0 , 1 , 0 , 2 , 0 , 0 , 0 , 0 },
+/* 1 : R */ { 0 , 1 , 3 , 3 , s(1,4), s(1,4), 0 , 1 },
+/* 2 : AN */ { 0 , 1 , 0 , 2 , s(1,5), s(1,5), 0 , 2 },
+/* 3 : R+EN/AN */ { 0 , 1 , 3 , 3 , s(1,4), s(1,4), 0 , 2 },
+/* 4 : R+ON */ { s(2,0), 1 , 3 , 3 , 4 , 4 , s(2,0), 1 },
+/* 5 : AN+ON */ { s(2,0), 1 , s(2,0), 2 , 5 , 5 , s(2,0), 1 }
+};
+static const ImpTab impTabR_DEFAULT = /* Odd paragraph level */
+/* In this table, conditional sequences receive the lower possible level
+ until proven otherwise.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 1 , 0 , 2 , 2 , 0 , 0 , 0 , 0 },
+/* 1 : L */ { 1 , 0 , 1 , 3 , s(1,4), s(1,4), 0 , 1 },
+/* 2 : EN/AN */ { 1 , 0 , 2 , 2 , 0 , 0 , 0 , 1 },
+/* 3 : L+AN */ { 1 , 0 , 1 , 3 , 5 , 5 , 0 , 1 },
+/* 4 : L+ON */ { s(2,1), 0 , s(2,1), 3 , 4 , 4 , 0 , 0 },
+/* 5 : L+AN+ON */ { 1 , 0 , 1 , 3 , 5 , 5 , 0 , 0 }
+};
+static const ImpAct impAct0 = {0,1,2,3,4,5,6};
+static const ImpTabPair impTab_DEFAULT = {{&impTabL_DEFAULT,
+ &impTabR_DEFAULT},
+ {&impAct0, &impAct0}};
+
+static const ImpTab impTabL_NUMBERS_SPECIAL = /* Even paragraph level */
+/* In this table, conditional sequences receive the higher possible level
+ until proven otherwise.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 0 , 2 , 1 , 1 , 0 , 0 , 0 , 0 },
+/* 1 : L+EN/AN */ { 0 , 2 , 1 , 1 , 0 , 0 , 0 , 2 },
+/* 2 : R */ { 0 , 2 , 4 , 4 , s(1,3), 0 , 0 , 1 },
+/* 3 : R+ON */ { s(2,0), 2 , 4 , 4 , 3 , 3 , s(2,0), 1 },
+/* 4 : R+EN/AN */ { 0 , 2 , 4 , 4 , s(1,3), s(1,3), 0 , 2 }
+ };
+static const ImpTabPair impTab_NUMBERS_SPECIAL = {{&impTabL_NUMBERS_SPECIAL,
+ &impTabR_DEFAULT},
+ {&impAct0, &impAct0}};
+
+static const ImpTab impTabL_GROUP_NUMBERS_WITH_R =
+/* In this table, EN/AN+ON sequences receive levels as if associated with R
+ until proven that there is L or sor/eor on both sides. AN is handled like EN.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 init */ { 0 , 3 , s(1,1), s(1,1), 0 , 0 , 0 , 0 },
+/* 1 EN/AN */ { s(2,0), 3 , 1 , 1 , 2 , s(2,0), s(2,0), 2 },
+/* 2 EN/AN+ON */ { s(2,0), 3 , 1 , 1 , 2 , s(2,0), s(2,0), 1 },
+/* 3 R */ { 0 , 3 , 5 , 5 , s(1,4), 0 , 0 , 1 },
+/* 4 R+ON */ { s(2,0), 3 , 5 , 5 , 4 , s(2,0), s(2,0), 1 },
+/* 5 R+EN/AN */ { 0 , 3 , 5 , 5 , s(1,4), 0 , 0 , 2 }
+};
+static const ImpTab impTabR_GROUP_NUMBERS_WITH_R =
+/* In this table, EN/AN+ON sequences receive levels as if associated with R
+ until proven that there is L on both sides. AN is handled like EN.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 init */ { 2 , 0 , 1 , 1 , 0 , 0 , 0 , 0 },
+/* 1 EN/AN */ { 2 , 0 , 1 , 1 , 0 , 0 , 0 , 1 },
+/* 2 L */ { 2 , 0 , s(1,4), s(1,4), s(1,3), 0 , 0 , 1 },
+/* 3 L+ON */ { s(2,2), 0 , 4 , 4 , 3 , 0 , 0 , 0 },
+/* 4 L+EN/AN */ { s(2,2), 0 , 4 , 4 , 3 , 0 , 0 , 1 }
+};
+static const ImpTabPair impTab_GROUP_NUMBERS_WITH_R = {
+ {&impTabL_GROUP_NUMBERS_WITH_R,
+ &impTabR_GROUP_NUMBERS_WITH_R},
+ {&impAct0, &impAct0}};
+
+
+static const ImpTab impTabL_INVERSE_NUMBERS_AS_L =
+/* This table is identical to the Default LTR table except that EN and AN are
+ handled like L.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 },
+/* 1 : R */ { 0 , 1 , 0 , 0 , s(1,4), s(1,4), 0 , 1 },
+/* 2 : AN */ { 0 , 1 , 0 , 0 , s(1,5), s(1,5), 0 , 2 },
+/* 3 : R+EN/AN */ { 0 , 1 , 0 , 0 , s(1,4), s(1,4), 0 , 2 },
+/* 4 : R+ON */ { s(2,0), 1 , s(2,0), s(2,0), 4 , 4 , s(2,0), 1 },
+/* 5 : AN+ON */ { s(2,0), 1 , s(2,0), s(2,0), 5 , 5 , s(2,0), 1 }
+};
+static const ImpTab impTabR_INVERSE_NUMBERS_AS_L =
+/* This table is identical to the Default RTL table except that EN and AN are
+ handled like L.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 },
+/* 1 : L */ { 1 , 0 , 1 , 1 , s(1,4), s(1,4), 0 , 1 },
+/* 2 : EN/AN */ { 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 },
+/* 3 : L+AN */ { 1 , 0 , 1 , 1 , 5 , 5 , 0 , 1 },
+/* 4 : L+ON */ { s(2,1), 0 , s(2,1), s(2,1), 4 , 4 , 0 , 0 },
+/* 5 : L+AN+ON */ { 1 , 0 , 1 , 1 , 5 , 5 , 0 , 0 }
+};
+static const ImpTabPair impTab_INVERSE_NUMBERS_AS_L = {
+ {&impTabL_INVERSE_NUMBERS_AS_L,
+ &impTabR_INVERSE_NUMBERS_AS_L},
+ {&impAct0, &impAct0}};
+
+static const ImpTab impTabR_INVERSE_LIKE_DIRECT = /* Odd paragraph level */
+/* In this table, conditional sequences receive the lower possible level
+ until proven otherwise.
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 1 , 0 , 2 , 2 , 0 , 0 , 0 , 0 },
+/* 1 : L */ { 1 , 0 , 1 , 2 , s(1,3), s(1,3), 0 , 1 },
+/* 2 : EN/AN */ { 1 , 0 , 2 , 2 , 0 , 0 , 0 , 1 },
+/* 3 : L+ON */ { s(2,1), s(3,0), 6 , 4 , 3 , 3 , s(3,0), 0 },
+/* 4 : L+ON+AN */ { s(2,1), s(3,0), 6 , 4 , 5 , 5 , s(3,0), 3 },
+/* 5 : L+AN+ON */ { s(2,1), s(3,0), 6 , 4 , 5 , 5 , s(3,0), 2 },
+/* 6 : L+ON+EN */ { s(2,1), s(3,0), 6 , 4 , 3 , 3 , s(3,0), 1 }
+};
+static const ImpAct impAct1 = {0,1,11,12};
+/* FOOD FOR THOUGHT: in LTR table below, check case "JKL 123abc"
+ */
+static const ImpTabPair impTab_INVERSE_LIKE_DIRECT = {
+ {&impTabL_DEFAULT,
+ &impTabR_INVERSE_LIKE_DIRECT},
+ {&impAct0, &impAct1}};
+
+static const ImpTab impTabL_INVERSE_LIKE_DIRECT_WITH_MARKS =
+/* The case handled in this table is (visually): R EN L
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 0 , s(6,3), 0 , 1 , 0 , 0 , 0 , 0 },
+/* 1 : L+AN */ { 0 , s(6,3), 0 , 1 , s(1,2), s(3,0), 0 , 4 },
+/* 2 : L+AN+ON */ { s(2,0), s(6,3), s(2,0), 1 , 2 , s(3,0), s(2,0), 3 },
+/* 3 : R */ { 0 , s(6,3), s(5,5), s(5,6), s(1,4), s(3,0), 0 , 3 },
+/* 4 : R+ON */ { s(3,0), s(4,3), s(5,5), s(5,6), 4 , s(3,0), s(3,0), 3 },
+/* 5 : R+EN */ { s(3,0), s(4,3), 5 , s(5,6), s(1,4), s(3,0), s(3,0), 4 },
+/* 6 : R+AN */ { s(3,0), s(4,3), s(5,5), 6 , s(1,4), s(3,0), s(3,0), 4 }
+};
+static const ImpTab impTabR_INVERSE_LIKE_DIRECT_WITH_MARKS =
+/* The cases handled in this table are (visually): R EN L
+ R L AN L
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { s(1,3), 0 , 1 , 1 , 0 , 0 , 0 , 0 },
+/* 1 : R+EN/AN */ { s(2,3), 0 , 1 , 1 , 2 , s(4,0), 0 , 1 },
+/* 2 : R+EN/AN+ON */ { s(2,3), 0 , 1 , 1 , 2 , s(4,0), 0 , 0 },
+/* 3 : L */ { 3 , 0 , 3 , s(3,6), s(1,4), s(4,0), 0 , 1 },
+/* 4 : L+ON */ { s(5,3), s(4,0), 5 , s(3,6), 4 , s(4,0), s(4,0), 0 },
+/* 5 : L+ON+EN */ { s(5,3), s(4,0), 5 , s(3,6), 4 , s(4,0), s(4,0), 1 },
+/* 6 : L+AN */ { s(5,3), s(4,0), 6 , 6 , 4 , s(4,0), s(4,0), 3 }
+};
+static const ImpAct impAct2 = {0,1,7,8,9,10};
+static const ImpTabPair impTab_INVERSE_LIKE_DIRECT_WITH_MARKS = {
+ {&impTabL_INVERSE_LIKE_DIRECT_WITH_MARKS,
+ &impTabR_INVERSE_LIKE_DIRECT_WITH_MARKS},
+ {&impAct0, &impAct2}};
+
+static const ImpTabPair impTab_INVERSE_FOR_NUMBERS_SPECIAL = {
+ {&impTabL_NUMBERS_SPECIAL,
+ &impTabR_INVERSE_LIKE_DIRECT},
+ {&impAct0, &impAct1}};
+
+static const ImpTab impTabL_INVERSE_FOR_NUMBERS_SPECIAL_WITH_MARKS =
+/* The case handled in this table is (visually): R EN L
+*/
+{
+/* L , R , EN , AN , ON , S , B , Res */
+/* 0 : init */ { 0 , s(6,2), 1 , 1 , 0 , 0 , 0 , 0 },
+/* 1 : L+EN/AN */ { 0 , s(6,2), 1 , 1 , 0 , s(3,0), 0 , 4 },
+/* 2 : R */ { 0 , s(6,2), s(5,4), s(5,4), s(1,3), s(3,0), 0 , 3 },
+/* 3 : R+ON */ { s(3,0), s(4,2), s(5,4), s(5,4), 3 , s(3,0), s(3,0), 3 },
+/* 4 : R+EN/AN */ { s(3,0), s(4,2), 4 , 4 , s(1,3), s(3,0), s(3,0), 4 }
+};
+static const ImpTabPair impTab_INVERSE_FOR_NUMBERS_SPECIAL_WITH_MARKS = {
+ {&impTabL_INVERSE_FOR_NUMBERS_SPECIAL_WITH_MARKS,
+ &impTabR_INVERSE_LIKE_DIRECT_WITH_MARKS},
+ {&impAct0, &impAct2}};
+
+#undef s
+
+typedef struct {
+ const ImpTab * pImpTab; /* level table pointer */
+ const ImpAct * pImpAct; /* action map array */
+ int32_t startON; /* start of ON sequence */
+ int32_t startL2EN; /* start of level 2 sequence */
+ int32_t lastStrongRTL; /* index of last found R or AL */
+ int32_t state; /* current state */
+ UBiDiLevel runLevel; /* run level before implicit solving */
+} LevState;
+
+/*------------------------------------------------------------------------*/
+
+static void
+addPoint(UBiDi *pBiDi, int32_t pos, int32_t flag)
+ /* param pos: position where to insert
+ param flag: one of LRM_BEFORE, LRM_AFTER, RLM_BEFORE, RLM_AFTER
+ */
+{
+#define FIRSTALLOC 10
+ Point point;
+ InsertPoints * pInsertPoints=&(pBiDi->insertPoints);
+
+ if (pInsertPoints->capacity == 0)
+ {
+ pInsertPoints->points=uprv_malloc(sizeof(Point)*FIRSTALLOC);
+ if (pInsertPoints->points == NULL)
+ {
+ pInsertPoints->errorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ pInsertPoints->capacity=FIRSTALLOC;
+ }
+ if (pInsertPoints->size >= pInsertPoints->capacity) /* no room for new point */
+ {
+ void * savePoints=pInsertPoints->points;
+ pInsertPoints->points=uprv_realloc(pInsertPoints->points,
+ pInsertPoints->capacity*2*sizeof(Point));
+ if (pInsertPoints->points == NULL)
+ {
+ pInsertPoints->points=savePoints;
+ pInsertPoints->errorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ else pInsertPoints->capacity*=2;
+ }
+ point.pos=pos;
+ point.flag=flag;
+ pInsertPoints->points[pInsertPoints->size]=point;
+ pInsertPoints->size++;
+#undef FIRSTALLOC
+}
+
+/* perform rules (Wn), (Nn), and (In) on a run of the text ------------------ */
+
+/*
+ * This implementation of the (Wn) rules applies all rules in one pass.
+ * In order to do so, it needs a look-ahead of typically 1 character
+ * (except for W5: sequences of ET) and keeps track of changes
+ * in a rule Wp that affect a later Wq (ppImpTab;
+ const ImpAct * pImpAct=pLevState->pImpAct;
+ UBiDiLevel * levels=pBiDi->levels;
+ UBiDiLevel level, addLevel;
+ InsertPoints * pInsertPoints;
+ int32_t start0, k;
+
+ start0=start; /* save original start position */
+ oldStateSeq=(uint8_t)pLevState->state;
+ cell=(*pImpTab)[oldStateSeq][_prop];
+ pLevState->state=GET_STATE(cell); /* isolate the new state */
+ actionSeq=(*pImpAct)[GET_ACTION(cell)]; /* isolate the action */
+ addLevel=(*pImpTab)[pLevState->state][IMPTABLEVELS_RES];
+
+ if(actionSeq) {
+ switch(actionSeq) {
+ case 1: /* init ON seq */
+ pLevState->startON=start0;
+ break;
+
+ case 2: /* prepend ON seq to current seq */
+ start=pLevState->startON;
+ break;
+
+ case 3: /* L or S after possible relevant EN/AN */
+ /* check if we had EN after R/AL */
+ if (pLevState->startL2EN >= 0) {
+ addPoint(pBiDi, pLevState->startL2EN, LRM_BEFORE);
+ }
+ pLevState->startL2EN=-1; /* not within previous if since could also be -2 */
+ /* check if we had any relevant EN/AN after R/AL */
+ pInsertPoints=&(pBiDi->insertPoints);
+ if ((pInsertPoints->capacity == 0) ||
+ (pInsertPoints->size <= pInsertPoints->confirmed))
+ {
+ /* nothing, just clean up */
+ pLevState->lastStrongRTL=-1;
+ /* check if we have a pending conditional segment */
+ level=(*pImpTab)[oldStateSeq][IMPTABLEVELS_RES];
+ if ((level & 1) && (pLevState->startON > 0)) { /* after ON */
+ start=pLevState->startON; /* reset to basic run level */
+ }
+ if (_prop == _S) /* add LRM before S */
+ {
+ addPoint(pBiDi, start0, LRM_BEFORE);
+ pInsertPoints->confirmed=pInsertPoints->size;
+ }
+ break;
+ }
+ /* reset previous RTL cont to level for LTR text */
+ for (k=pLevState->lastStrongRTL+1; kconfirmed=pInsertPoints->size;
+ pLevState->lastStrongRTL=-1;
+ if (_prop == _S) /* add LRM before S */
+ {
+ addPoint(pBiDi, start0, LRM_BEFORE);
+ pInsertPoints->confirmed=pInsertPoints->size;
+ }
+ break;
+
+ case 4: /* R/AL after possible relevant EN/AN */
+ /* just clean up */
+ pInsertPoints=&(pBiDi->insertPoints);
+ if (pInsertPoints->capacity > 0)
+ /* remove all non confirmed insert points */
+ pInsertPoints->size=pInsertPoints->confirmed;
+ pLevState->startON=-1;
+ pLevState->startL2EN=-1;
+ pLevState->lastStrongRTL=limit - 1;
+ break;
+
+ case 5: /* EN/AN after R/AL + possible cont */
+ /* check for real AN */
+ if ((_prop == _AN) && (NO_CONTEXT_RTL(pBiDi->dirProps[start0]) == AN) &&
+ (pBiDi->reorderingMode!=UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL))
+ {
+ /* real AN */
+ if (pLevState->startL2EN == -1) /* if no relevant EN already found */
+ {
+ /* just note the righmost digit as a strong RTL */
+ pLevState->lastStrongRTL=limit - 1;
+ break;
+ }
+ if (pLevState->startL2EN >= 0) /* after EN, no AN */
+ {
+ addPoint(pBiDi, pLevState->startL2EN, LRM_BEFORE);
+ pLevState->startL2EN=-2;
+ }
+ /* note AN */
+ addPoint(pBiDi, start0, LRM_BEFORE);
+ break;
+ }
+ /* if first EN/AN after R/AL */
+ if (pLevState->startL2EN == -1) {
+ pLevState->startL2EN=start0;
+ }
+ break;
+
+ case 6: /* note location of latest R/AL */
+ pLevState->lastStrongRTL=limit - 1;
+ pLevState->startON=-1;
+ break;
+
+ case 7: /* L after R+ON/EN/AN */
+ /* include possible adjacent number on the left */
+ for (k=start0-1; k>=0 && !(levels[k]&1); k--);
+ if(k>=0) {
+ addPoint(pBiDi, k, RLM_BEFORE); /* add RLM before */
+ pInsertPoints=&(pBiDi->insertPoints);
+ pInsertPoints->confirmed=pInsertPoints->size; /* confirm it */
+ }
+ pLevState->startON=start0;
+ break;
+
+ case 8: /* AN after L */
+ /* AN numbers between L text on both sides may be trouble. */
+ /* tentatively bracket with LRMs; will be confirmed if followed by L */
+ addPoint(pBiDi, start0, LRM_BEFORE); /* add LRM before */
+ addPoint(pBiDi, start0, LRM_AFTER); /* add LRM after */
+ break;
+
+ case 9: /* R after L+ON/EN/AN */
+ /* false alert, infirm LRMs around previous AN */
+ pInsertPoints=&(pBiDi->insertPoints);
+ pInsertPoints->size=pInsertPoints->confirmed;
+ if (_prop == _S) /* add RLM before S */
+ {
+ addPoint(pBiDi, start0, RLM_BEFORE);
+ pInsertPoints->confirmed=pInsertPoints->size;
+ }
+ break;
+
+ case 10: /* L after L+ON/AN */
+ level=pLevState->runLevel + addLevel;
+ for(k=pLevState->startON; kinsertPoints);
+ pInsertPoints->confirmed=pInsertPoints->size; /* confirm inserts */
+ pLevState->startON=start0;
+ break;
+
+ case 11: /* L after L+ON+EN/AN/ON */
+ level=pLevState->runLevel;
+ for(k=start0-1; k>=pLevState->startON; k--) {
+ if(levels[k]==level+3) {
+ while(levels[k]==level+3) {
+ levels[k--]-=2;
+ }
+ while(levels[k]==level) {
+ k--;
+ }
+ }
+ if(levels[k]==level+2) {
+ levels[k]=level;
+ continue;
+ }
+ levels[k]=level+1;
+ }
+ break;
+
+ case 12: /* R after L+ON+EN/AN/ON */
+ level=pLevState->runLevel+1;
+ for(k=start0-1; k>=pLevState->startON; k--) {
+ if(levels[k]>level) {
+ levels[k]-=2;
+ }
+ }
+ break;
+
+ default: /* we should never get here */
+ U_ASSERT(FALSE);
+ break;
+ }
+ }
+ if((addLevel) || (start < start0)) {
+ level=pLevState->runLevel + addLevel;
+ for(k=start; kdirProps;
+
+ LevState levState;
+ int32_t i, start1, start2;
+ uint8_t oldStateImp, stateImp, actionImp;
+ uint8_t gprop, resProp, cell;
+ UBool inverseRTL;
+ DirProp nextStrongProp=R;
+ int32_t nextStrongPos=-1;
+
+ /* check for RTL inverse BiDi mode */
+ /* FOOD FOR THOUGHT: in case of RTL inverse BiDi, it would make sense to
+ * loop on the text characters from end to start.
+ * This would need a different properties state table (at least different
+ * actions) and different levels state tables (maybe very similar to the
+ * LTR corresponding ones.
+ */
+ inverseRTL=(UBool)
+ ((startlastArabicPos) && (GET_PARALEVEL(pBiDi, start) & 1) &&
+ (pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
+ pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL));
+ /* initialize for levels state table */
+ levState.startL2EN=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
+ levState.lastStrongRTL=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
+ levState.state=0;
+ levState.runLevel=pBiDi->levels[start];
+ levState.pImpTab=(const ImpTab*)((pBiDi->pImpTabPair)->pImpTab)[levState.runLevel&1];
+ levState.pImpAct=(const ImpAct*)((pBiDi->pImpTabPair)->pImpAct)[levState.runLevel&1];
+ processPropertySeq(pBiDi, &levState, sor, start, start);
+ /* initialize for property state table */
+ if(dirProps[start]==NSM) {
+ stateImp = 1 + sor;
+ } else {
+ stateImp=0;
+ }
+ start1=start;
+ start2=start;
+
+ for(i=start; i<=limit; i++) {
+ if(i>=limit) {
+ gprop=eor;
+ } else {
+ DirProp prop, prop1;
+ prop=NO_CONTEXT_RTL(dirProps[i]);
+ if(inverseRTL) {
+ if(prop==AL) {
+ /* AL before EN does not make it AN */
+ prop=R;
+ } else if(prop==EN) {
+ if(nextStrongPos<=i) {
+ /* look for next strong char (L/R/AL) */
+ int32_t j;
+ nextStrongProp=R; /* set default */
+ nextStrongPos=limit;
+ for(j=i+1; jdirProps;
+ UBiDiLevel *levels=pBiDi->levels;
+ int32_t i;
+
+ if(pBiDi->flags&MASK_WS) {
+ UBool orderParagraphsLTR=pBiDi->orderParagraphsLTR;
+ Flags flag;
+
+ i=pBiDi->trailingWSStart;
+ while(i>0) {
+ /* reset a sequence of WS/BN before eop and B/S to the paragraph paraLevel */
+ while(i>0 && (flag=DIRPROP_FLAG_NC(dirProps[--i]))&MASK_WS) {
+ if(orderParagraphsLTR&&(flag&DIRPROP_FLAG(B))) {
+ levels[i]=0;
+ } else {
+ levels[i]=GET_PARALEVEL(pBiDi, i);
+ }
+ }
+
+ /* reset BN to the next character's paraLevel until B/S, which restarts above loop */
+ /* here, i+1 is guaranteed to be 0) {
+ flag=DIRPROP_FLAG_NC(dirProps[--i]);
+ if(flag&MASK_BN_EXPLICIT) {
+ levels[i]=levels[i+1];
+ } else if(orderParagraphsLTR&&(flag&DIRPROP_FLAG(B))) {
+ levels[i]=0;
+ break;
+ } else if(flag&MASK_B_S) {
+ levels[i]=GET_PARALEVEL(pBiDi, i);
+ break;
+ }
+ }
+ }
+ }
+}
+
+#define BIDI_MIN(x, y) ((x)<(y) ? (x) : (y))
+#define BIDI_ABS(x) ((x)>=0 ? (x) : (-(x)))
+static void
+setParaRunsOnly(UBiDi *pBiDi, const UChar *text, int32_t length,
+ UBiDiLevel paraLevel, UErrorCode *pErrorCode) {
+ void *runsOnlyMemory;
+ int32_t *visualMap;
+ UChar *visualText;
+ int32_t saveLength, saveTrailingWSStart;
+ const UBiDiLevel *levels;
+ UBiDiLevel *saveLevels;
+ UBiDiDirection saveDirection;
+ UBool saveMayAllocateText;
+ Run *runs;
+ int32_t visualLength, i, j, visualStart, logicalStart,
+ runCount, runLength, addedRuns, insertRemove,
+ start, limit, step, indexOddBit, logicalPos,
+ index, index1;
+ uint32_t saveOptions;
+
+ pBiDi->reorderingMode=UBIDI_REORDER_DEFAULT;
+ if(length==0) {
+ ubidi_setPara(pBiDi, text, length, paraLevel, NULL, pErrorCode);
+ goto cleanup3;
+ }
+ /* obtain memory for mapping table and visual text */
+ runsOnlyMemory=uprv_malloc(length*(sizeof(int32_t)+sizeof(UChar)+sizeof(UBiDiLevel)));
+ if(runsOnlyMemory==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup3;
+ }
+ visualMap=runsOnlyMemory;
+ visualText=(UChar *)&visualMap[length];
+ saveLevels=(UBiDiLevel *)&visualText[length];
+ saveOptions=pBiDi->reorderingOptions;
+ if(saveOptions & UBIDI_OPTION_INSERT_MARKS) {
+ pBiDi->reorderingOptions&=~UBIDI_OPTION_INSERT_MARKS;
+ pBiDi->reorderingOptions|=UBIDI_OPTION_REMOVE_CONTROLS;
+ }
+ paraLevel&=1; /* accept only 0 or 1 */
+ ubidi_setPara(pBiDi, text, length, paraLevel, NULL, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ goto cleanup3;
+ }
+ /* we cannot access directly pBiDi->levels since it is not yet set if
+ * direction is not MIXED
+ */
+ levels=ubidi_getLevels(pBiDi, pErrorCode);
+ uprv_memcpy(saveLevels, levels, pBiDi->length*sizeof(UBiDiLevel));
+ saveTrailingWSStart=pBiDi->trailingWSStart;
+ saveLength=pBiDi->length;
+ saveDirection=pBiDi->direction;
+
+ /* FOOD FOR THOUGHT: instead of writing the visual text, we could use
+ * the visual map and the dirProps array to drive the second call
+ * to ubidi_setPara (but must make provision for possible removal of
+ * BiDi controls. Alternatively, only use the dirProps array via
+ * customized classifier callback.
+ */
+ visualLength=ubidi_writeReordered(pBiDi, visualText, length,
+ UBIDI_DO_MIRRORING, pErrorCode);
+ ubidi_getVisualMap(pBiDi, visualMap, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ goto cleanup2;
+ }
+ pBiDi->reorderingOptions=saveOptions;
+
+ pBiDi->reorderingMode=UBIDI_REORDER_INVERSE_LIKE_DIRECT;
+ paraLevel^=1;
+ /* Because what we did with reorderingOptions, visualText may be shorter
+ * than the original text. But we don't want the levels memory to be
+ * reallocated shorter than the original length, since we need to restore
+ * the levels as after the first call to ubidi_setpara() before returning.
+ * We will force mayAllocateText to FALSE before the second call to
+ * ubidi_setpara(), and will restore it afterwards.
+ */
+ saveMayAllocateText=pBiDi->mayAllocateText;
+ pBiDi->mayAllocateText=FALSE;
+ ubidi_setPara(pBiDi, visualText, visualLength, paraLevel, NULL, pErrorCode);
+ pBiDi->mayAllocateText=saveMayAllocateText;
+ ubidi_getRuns(pBiDi, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ goto cleanup1;
+ }
+ /* check if some runs must be split, count how many splits */
+ addedRuns=0;
+ runCount=pBiDi->runCount;
+ runs=pBiDi->runs;
+ visualStart=0;
+ for(i=0; irunsMemory[0]=runs[0];
+ }
+ runs=pBiDi->runs=pBiDi->runsMemory;
+ pBiDi->runCount+=addedRuns;
+ } else {
+ goto cleanup1;
+ }
+ }
+ /* split runs which are not consecutive in source text */
+ for(i=runCount-1; i>=0; i--) {
+ runLength= i==0 ? runs[0].visualLimit :
+ runs[i].visualLimit-runs[i-1].visualLimit;
+ logicalStart=runs[i].logicalStart;
+ indexOddBit=GET_ODD_BIT(logicalStart);
+ logicalStart=GET_INDEX(logicalStart);
+ if(runLength<2) {
+ if(addedRuns) {
+ runs[i+addedRuns]=runs[i];
+ }
+ logicalPos=visualMap[logicalStart];
+ runs[i+addedRuns].logicalStart=MAKE_INDEX_ODD_PAIR(logicalPos,
+ saveLevels[logicalPos]^indexOddBit);
+ continue;
+ }
+ if(indexOddBit) {
+ start=logicalStart;
+ limit=logicalStart+runLength-1;
+ step=1;
+ } else {
+ start=logicalStart+runLength-1;
+ limit=logicalStart;
+ step=-1;
+ }
+ for(j=start; j!=limit; j+=step) {
+ index=visualMap[j];
+ index1=visualMap[j+step];
+ if((BIDI_ABS(index-index1)!=1) || (saveLevels[index]!=saveLevels[index1])) {
+ logicalPos=BIDI_MIN(visualMap[start], index);
+ runs[i+addedRuns].logicalStart=MAKE_INDEX_ODD_PAIR(logicalPos,
+ saveLevels[logicalPos]^indexOddBit);
+ runs[i+addedRuns].visualLimit=runs[i].visualLimit;
+ runs[i].visualLimit-=BIDI_ABS(j-start)+1;
+ insertRemove=runs[i].insertRemove&(LRM_AFTER|RLM_AFTER);
+ runs[i+addedRuns].insertRemove=insertRemove;
+ runs[i].insertRemove&=~insertRemove;
+ start=j+step;
+ addedRuns--;
+ }
+ }
+ if(addedRuns) {
+ runs[i+addedRuns]=runs[i];
+ }
+ logicalPos=BIDI_MIN(visualMap[start], visualMap[limit]);
+ runs[i+addedRuns].logicalStart=MAKE_INDEX_ODD_PAIR(logicalPos,
+ saveLevels[logicalPos]^indexOddBit);
+ }
+
+ cleanup1:
+ /* restore initial paraLevel */
+ pBiDi->paraLevel^=1;
+ cleanup2:
+ /* restore real text */
+ pBiDi->text=text;
+ pBiDi->length=saveLength;
+ pBiDi->originalLength=length;
+ pBiDi->direction=saveDirection;
+ /* the saved levels should never excess levelsSize, but we check anyway */
+ if(saveLength>pBiDi->levelsSize) {
+ saveLength=pBiDi->levelsSize;
+ }
+ uprv_memcpy(pBiDi->levels, saveLevels, saveLength*sizeof(UBiDiLevel));
+ pBiDi->trailingWSStart=saveTrailingWSStart;
+ /* free memory for mapping table and visual text */
+ uprv_free(runsOnlyMemory);
+ if(pBiDi->runCount>1) {
+ pBiDi->direction=UBIDI_MIXED;
+ }
+ cleanup3:
+ pBiDi->reorderingMode=UBIDI_REORDER_RUNS_ONLY;
+}
+
+/* ubidi_setPara ------------------------------------------------------------ */
+
+U_CAPI void U_EXPORT2
+ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
+ UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
+ UErrorCode *pErrorCode) {
+ UBiDiDirection direction;
+
+ /* check the argument values */
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ if(pBiDi==NULL || text==NULL || length<-1 ||
+ (paraLevel>UBIDI_MAX_EXPLICIT_LEVEL && paraLevelreorderingMode==UBIDI_REORDER_RUNS_ONLY) {
+ setParaRunsOnly(pBiDi, text, length, paraLevel, pErrorCode);
+ return;
+ }
+
+ /* initialize the UBiDi structure */
+ pBiDi->pParaBiDi=NULL; /* mark unfinished setPara */
+ pBiDi->text=text;
+ pBiDi->length=pBiDi->originalLength=pBiDi->resultLength=length;
+ pBiDi->paraLevel=paraLevel;
+ pBiDi->direction=UBIDI_LTR;
+ pBiDi->paraCount=1;
+
+ pBiDi->dirProps=NULL;
+ pBiDi->levels=NULL;
+ pBiDi->runs=NULL;
+ pBiDi->insertPoints.size=0; /* clean up from last call */
+ pBiDi->insertPoints.confirmed=0; /* clean up from last call */
+
+ /*
+ * Save the original paraLevel if contextual; otherwise, set to 0.
+ */
+ if(IS_DEFAULT_LEVEL(paraLevel)) {
+ pBiDi->defaultParaLevel=paraLevel;
+ } else {
+ pBiDi->defaultParaLevel=0;
+ }
+
+ if(length==0) {
+ /*
+ * For an empty paragraph, create a UBiDi object with the paraLevel and
+ * the flags and the direction set but without allocating zero-length arrays.
+ * There is nothing more to do.
+ */
+ if(IS_DEFAULT_LEVEL(paraLevel)) {
+ pBiDi->paraLevel&=1;
+ pBiDi->defaultParaLevel=0;
+ }
+ if(paraLevel&1) {
+ pBiDi->flags=DIRPROP_FLAG(R);
+ pBiDi->direction=UBIDI_RTL;
+ } else {
+ pBiDi->flags=DIRPROP_FLAG(L);
+ pBiDi->direction=UBIDI_LTR;
+ }
+
+ pBiDi->runCount=0;
+ pBiDi->paraCount=0;
+ pBiDi->pParaBiDi=pBiDi; /* mark successful setPara */
+ return;
+ }
+
+ pBiDi->runCount=-1;
+
+ /*
+ * Get the directional properties,
+ * the flags bit-set, and
+ * determine the paragraph level if necessary.
+ */
+ if(getDirPropsMemory(pBiDi, length)) {
+ pBiDi->dirProps=pBiDi->dirPropsMemory;
+ getDirProps(pBiDi);
+ } else {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ /* the processed length may have changed if UBIDI_OPTION_STREAMING */
+ length= pBiDi->length;
+ pBiDi->trailingWSStart=length; /* the levels[] will reflect the WS run */
+ /* allocate paras memory */
+ if(pBiDi->paraCount>1) {
+ if(getInitialParasMemory(pBiDi, pBiDi->paraCount)) {
+ pBiDi->paras=pBiDi->parasMemory;
+ pBiDi->paras[pBiDi->paraCount-1]=length;
+ } else {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ } else {
+ /* initialize paras for single paragraph */
+ pBiDi->paras=pBiDi->simpleParas;
+ pBiDi->simpleParas[0]=length;
+ }
+
+ /* are explicit levels specified? */
+ if(embeddingLevels==NULL) {
+ /* no: determine explicit levels according to the (Xn) rules */\
+ if(getLevelsMemory(pBiDi, length)) {
+ pBiDi->levels=pBiDi->levelsMemory;
+ direction=resolveExplicitLevels(pBiDi);
+ } else {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ } else {
+ /* set BN for all explicit codes, check that all levels are 0 or paraLevel..UBIDI_MAX_EXPLICIT_LEVEL */
+ pBiDi->levels=embeddingLevels;
+ direction=checkExplicitLevels(pBiDi, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+ }
+
+ /*
+ * The steps after (X9) in the UBiDi algorithm are performed only if
+ * the paragraph text has mixed directionality!
+ */
+ pBiDi->direction=direction;
+ switch(direction) {
+ case UBIDI_LTR:
+ /* make sure paraLevel is even */
+ pBiDi->paraLevel=(UBiDiLevel)((pBiDi->paraLevel+1)&~1);
+
+ /* all levels are implicitly at paraLevel (important for ubidi_getLevels()) */
+ pBiDi->trailingWSStart=0;
+ break;
+ case UBIDI_RTL:
+ /* make sure paraLevel is odd */
+ pBiDi->paraLevel|=1;
+
+ /* all levels are implicitly at paraLevel (important for ubidi_getLevels()) */
+ pBiDi->trailingWSStart=0;
+ break;
+ default:
+ /*
+ * Choose the right implicit state table
+ */
+ switch(pBiDi->reorderingMode) {
+ case UBIDI_REORDER_DEFAULT:
+ pBiDi->pImpTabPair=&impTab_DEFAULT;
+ break;
+ case UBIDI_REORDER_NUMBERS_SPECIAL:
+ pBiDi->pImpTabPair=&impTab_NUMBERS_SPECIAL;
+ break;
+ case UBIDI_REORDER_GROUP_NUMBERS_WITH_R:
+ pBiDi->pImpTabPair=&impTab_GROUP_NUMBERS_WITH_R;
+ break;
+ case UBIDI_REORDER_INVERSE_NUMBERS_AS_L:
+ pBiDi->pImpTabPair=&impTab_INVERSE_NUMBERS_AS_L;
+ break;
+ case UBIDI_REORDER_INVERSE_LIKE_DIRECT:
+ if (pBiDi->reorderingOptions & UBIDI_OPTION_INSERT_MARKS) {
+ pBiDi->pImpTabPair=&impTab_INVERSE_LIKE_DIRECT_WITH_MARKS;
+ } else {
+ pBiDi->pImpTabPair=&impTab_INVERSE_LIKE_DIRECT;
+ }
+ break;
+ case UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL:
+ if (pBiDi->reorderingOptions & UBIDI_OPTION_INSERT_MARKS) {
+ pBiDi->pImpTabPair=&impTab_INVERSE_FOR_NUMBERS_SPECIAL_WITH_MARKS;
+ } else {
+ pBiDi->pImpTabPair=&impTab_INVERSE_FOR_NUMBERS_SPECIAL;
+ }
+ break;
+ default:
+ /* we should never get here */
+ U_ASSERT(FALSE);
+ break;
+ }
+ /*
+ * If there are no external levels specified and there
+ * are no significant explicit level codes in the text,
+ * then we can treat the entire paragraph as one run.
+ * Otherwise, we need to perform the following rules on runs of
+ * the text with the same embedding levels. (X10)
+ * "Significant" explicit level codes are ones that actually
+ * affect non-BN characters.
+ * Examples for "insignificant" ones are empty embeddings
+ * LRE-PDF, LRE-RLE-PDF-PDF, etc.
+ */
+ if(embeddingLevels==NULL && pBiDi->paraCount<=1 &&
+ !(pBiDi->flags&DIRPROP_FLAG_MULTI_RUNS)) {
+ resolveImplicitLevels(pBiDi, 0, length,
+ GET_LR_FROM_LEVEL(GET_PARALEVEL(pBiDi, 0)),
+ GET_LR_FROM_LEVEL(GET_PARALEVEL(pBiDi, length-1)));
+ } else {
+ /* sor, eor: start and end types of same-level-run */
+ UBiDiLevel *levels=pBiDi->levels;
+ int32_t start, limit=0;
+ UBiDiLevel level, nextLevel;
+ DirProp sor, eor;
+
+ /* determine the first sor and set eor to it because of the loop body (sor=eor there) */
+ level=GET_PARALEVEL(pBiDi, 0);
+ nextLevel=levels[0];
+ if(level0) && (NO_CONTEXT_RTL(pBiDi->dirProps[start-1])==B)) {
+ /* except if this is a new paragraph, then set sor = para level */
+ sor=GET_LR_FROM_LEVEL(GET_PARALEVEL(pBiDi, start));
+ } else {
+ sor=eor;
+ }
+
+ /* search for the limit of this run */
+ while(++limitinsertPoints.errorCode))
+ {
+ *pErrorCode=pBiDi->insertPoints.errorCode;
+ return;
+ }
+ /* reset the embedding levels for some non-graphic characters (L1), (X9) */
+ adjustWSLevels(pBiDi);
+ break;
+ }
+ /* add RLM for inverse Bidi with contextual orientation resolving
+ * to RTL which would not round-trip otherwise
+ */
+ if((pBiDi->defaultParaLevel>0) &&
+ (pBiDi->reorderingOptions & UBIDI_OPTION_INSERT_MARKS) &&
+ ((pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT) ||
+ (pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL))) {
+ int32_t i, j, start, last;
+ DirProp dirProp;
+ for(i=0; iparaCount; i++) {
+ last=pBiDi->paras[i]-1;
+ if((pBiDi->dirProps[last] & CONTEXT_RTL)==0) {
+ continue; /* LTR paragraph */
+ }
+ start= i==0 ? 0 : pBiDi->paras[i - 1];
+ for(j=last; j>=start; j--) {
+ dirProp=NO_CONTEXT_RTL(pBiDi->dirProps[j]);
+ if(dirProp==L) {
+ if(jdirProps[last])==B) {
+ last--;
+ }
+ }
+ addPoint(pBiDi, last, RLM_BEFORE);
+ break;
+ }
+ if(DIRPROP_FLAG(dirProp) & MASK_R_AL) {
+ break;
+ }
+ }
+ }
+ }
+
+ if(pBiDi->reorderingOptions & UBIDI_OPTION_REMOVE_CONTROLS) {
+ pBiDi->resultLength -= pBiDi->controlCount;
+ } else {
+ pBiDi->resultLength += pBiDi->insertPoints.size;
+ }
+ pBiDi->pParaBiDi=pBiDi; /* mark successful setPara */
+}
+
+U_CAPI void U_EXPORT2
+ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR) {
+ if(pBiDi!=NULL) {
+ pBiDi->orderParagraphsLTR=orderParagraphsLTR;
+ }
+}
+
+U_CAPI UBool U_EXPORT2
+ubidi_isOrderParagraphsLTR(UBiDi *pBiDi) {
+ if(pBiDi!=NULL) {
+ return pBiDi->orderParagraphsLTR;
+ } else {
+ return FALSE;
+ }
+}
+
+U_CAPI UBiDiDirection U_EXPORT2
+ubidi_getDirection(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->direction;
+ } else {
+ return UBIDI_LTR;
+ }
+}
+
+U_CAPI const UChar * U_EXPORT2
+ubidi_getText(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->text;
+ } else {
+ return NULL;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getLength(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->originalLength;
+ } else {
+ return 0;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getProcessedLength(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->length;
+ } else {
+ return 0;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getResultLength(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->resultLength;
+ } else {
+ return 0;
+ }
+}
+
+/* paragraphs API functions ------------------------------------------------- */
+
+U_CAPI UBiDiLevel U_EXPORT2
+ubidi_getParaLevel(const UBiDi *pBiDi) {
+ if(IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return pBiDi->paraLevel;
+ } else {
+ return 0;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_countParagraphs(UBiDi *pBiDi) {
+ if(!IS_VALID_PARA_OR_LINE(pBiDi)) {
+ return 0;
+ } else {
+ return pBiDi->paraCount;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
+ int32_t *pParaStart, int32_t *pParaLimit,
+ UBiDiLevel *pParaLevel, UErrorCode *pErrorCode) {
+ int32_t paraStart;
+
+ /* check the argument values */
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ RETURN_VOID_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode);
+ RETURN_VOID_IF_BAD_RANGE(paraIndex, 0, pBiDi->paraCount, *pErrorCode);
+
+ pBiDi=pBiDi->pParaBiDi; /* get Para object if Line object */
+ if(paraIndex) {
+ paraStart=pBiDi->paras[paraIndex-1];
+ } else {
+ paraStart=0;
+ }
+ if(pParaStart!=NULL) {
+ *pParaStart=paraStart;
+ }
+ if(pParaLimit!=NULL) {
+ *pParaLimit=pBiDi->paras[paraIndex];
+ }
+ if(pParaLevel!=NULL) {
+ *pParaLevel=GET_PARALEVEL(pBiDi, paraStart);
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex,
+ int32_t *pParaStart, int32_t *pParaLimit,
+ UBiDiLevel *pParaLevel, UErrorCode *pErrorCode) {
+ uint32_t paraIndex;
+
+ /* check the argument values */
+ /* pErrorCode will be checked by the call to ubidi_getParagraphByIndex */
+ RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrorCode, -1);
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode, -1);
+ pBiDi=pBiDi->pParaBiDi; /* get Para object if Line object */
+ RETURN_IF_BAD_RANGE(charIndex, 0, pBiDi->length, *pErrorCode, -1);
+
+ for(paraIndex=0; charIndex>=pBiDi->paras[paraIndex]; paraIndex++);
+ ubidi_getParagraphByIndex(pBiDi, paraIndex, pParaStart, pParaLimit, pParaLevel, pErrorCode);
+ return paraIndex;
+}
+
+U_CAPI void U_EXPORT2
+ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
+ const void *newContext, UBiDiClassCallback **oldFn,
+ const void **oldContext, UErrorCode *pErrorCode)
+{
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ if(pBiDi==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if( oldFn )
+ {
+ *oldFn = pBiDi->fnClassCallback;
+ }
+ if( oldContext )
+ {
+ *oldContext = pBiDi->coClassCallback;
+ }
+ pBiDi->fnClassCallback = newFn;
+ pBiDi->coClassCallback = newContext;
+}
+
+U_CAPI void U_EXPORT2
+ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context)
+{
+ if(pBiDi==NULL) {
+ return;
+ }
+ if( fn )
+ {
+ *fn = pBiDi->fnClassCallback;
+ }
+ if( context )
+ {
+ *context = pBiDi->coClassCallback;
+ }
+}
+
+U_CAPI UCharDirection U_EXPORT2
+ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c)
+{
+ UCharDirection dir;
+
+ if( pBiDi->fnClassCallback == NULL ||
+ (dir = (*pBiDi->fnClassCallback)(pBiDi->coClassCallback, c)) == U_BIDI_CLASS_DEFAULT )
+ {
+ return ubidi_getClass(pBiDi->bdp, c);
+ } else {
+ return dir;
+ }
+}
+
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidi_props.c b/Build/source/libs/icu/icu-xetex/common/ubidi_props.c
new file mode 100644
index 00000000000..010a3db05d4
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidi_props.c
@@ -0,0 +1,520 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2004-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: ubidi_props.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004dec30
+* created by: Markus W. Scherer
+*
+* Low-level Unicode bidi/shaping properties access.
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "unicode/udata.h" /* UDataInfo */
+#include "ucmndata.h" /* DataHeader */
+#include "udatamem.h"
+#include "umutex.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "utrie.h"
+#include "ubidi_props.h"
+#include "ucln_cmn.h"
+
+struct UBiDiProps {
+ UDataMemory *mem;
+ const int32_t *indexes;
+ const uint32_t *mirrors;
+ const uint8_t *jgArray;
+
+ UTrie trie;
+ uint8_t formatVersion[4];
+};
+
+/* data loading etc. -------------------------------------------------------- */
+
+#define UBIDI_HARDCODE_DATA 1
+
+#if UBIDI_HARDCODE_DATA
+
+/* ubidi_props_data.c is machine-generated by genbidi --csource */
+#include "ubidi_props_data.c"
+
+#else
+
+static UBool U_CALLCONV
+isAcceptable(void *context,
+ const char *type, const char *name,
+ const UDataInfo *pInfo) {
+ if(
+ pInfo->size>=20 &&
+ pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
+ pInfo->charsetFamily==U_CHARSET_FAMILY &&
+ pInfo->dataFormat[0]==UBIDI_FMT_0 && /* dataFormat="BiDi" */
+ pInfo->dataFormat[1]==UBIDI_FMT_1 &&
+ pInfo->dataFormat[2]==UBIDI_FMT_2 &&
+ pInfo->dataFormat[3]==UBIDI_FMT_3 &&
+ pInfo->formatVersion[0]==1 &&
+ pInfo->formatVersion[2]==UTRIE_SHIFT &&
+ pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
+ ) {
+ UBiDiProps *bdp=(UBiDiProps *)context;
+ uprv_memcpy(bdp->formatVersion, pInfo->formatVersion, 4);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static UBiDiProps *
+ubidi_openData(UBiDiProps *bdpProto,
+ const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
+ UBiDiProps *bdp;
+ int32_t size;
+
+ bdpProto->indexes=(const int32_t *)bin;
+ if( (length>=0 && length<16*4) ||
+ bdpProto->indexes[UBIDI_IX_INDEX_TOP]<16
+ ) {
+ /* length or indexes[] too short for minimum indexes[] length of 16 */
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ size=bdpProto->indexes[UBIDI_IX_INDEX_TOP]*4;
+ if(length>=0) {
+ if(length>=size && length>=bdpProto->indexes[UBIDI_IX_LENGTH]) {
+ length-=size;
+ } else {
+ /* length too short for indexes[] or for the whole data length */
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ }
+ bin+=size;
+ /* from here on, assume that the sizes of the items fit into the total length */
+
+ /* unserialize the trie, after indexes[] */
+ size=bdpProto->indexes[UBIDI_IX_TRIE_SIZE];
+ utrie_unserialize(&bdpProto->trie, bin, size, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ bin+=size;
+
+ /* get mirrors[] */
+ size=4*bdpProto->indexes[UBIDI_IX_MIRROR_LENGTH];
+ bdpProto->mirrors=(const uint32_t *)bin;
+ bin+=size;
+
+ /* get jgArray[] */
+ size=bdpProto->indexes[UBIDI_IX_JG_LIMIT]-bdpProto->indexes[UBIDI_IX_JG_START];
+ bdpProto->jgArray=bin;
+ bin+=size;
+
+ /* allocate, copy, and return the new UBiDiProps */
+ bdp=(UBiDiProps *)uprv_malloc(sizeof(UBiDiProps));
+ if(bdp==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ } else {
+ uprv_memcpy(bdp, bdpProto, sizeof(UBiDiProps));
+ return bdp;
+ }
+}
+
+U_CFUNC UBiDiProps *
+ubidi_openProps(UErrorCode *pErrorCode) {
+ UBiDiProps bdpProto={ NULL }, *bdp;
+
+ bdpProto.mem=udata_openChoice(NULL, UBIDI_DATA_TYPE, UBIDI_DATA_NAME, isAcceptable, &bdpProto, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ bdp=ubidi_openData(
+ &bdpProto,
+ udata_getMemory(bdpProto.mem),
+ udata_getLength(bdpProto.mem),
+ pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ udata_close(bdpProto.mem);
+ return NULL;
+ } else {
+ return bdp;
+ }
+}
+
+U_CFUNC UBiDiProps *
+ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
+ UBiDiProps bdpProto={ NULL };
+ const DataHeader *hdr;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ if(bin==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ /* check the header */
+ if(length>=0 && length<20) {
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ hdr=(const DataHeader *)bin;
+ if(
+ !(hdr->dataHeader.magic1==0xda && hdr->dataHeader.magic2==0x27 &&
+ hdr->info.isBigEndian==U_IS_BIG_ENDIAN &&
+ isAcceptable(&bdpProto, UBIDI_DATA_TYPE, UBIDI_DATA_NAME, &hdr->info))
+ ) {
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+
+ bin+=hdr->dataHeader.headerSize;
+ if(length>=0) {
+ length-=hdr->dataHeader.headerSize;
+ }
+ return ubidi_openData(&bdpProto, bin, length, pErrorCode);
+}
+
+#endif
+
+U_CFUNC void
+ubidi_closeProps(UBiDiProps *bdp) {
+ if(bdp!=NULL) {
+#if !UBIDI_HARDCODE_DATA
+ udata_close(bdp->mem);
+#endif
+ uprv_free(bdp);
+ }
+}
+
+/* UBiDiProps singleton ----------------------------------------------------- */
+
+static UBiDiProps *gBdpDummy=NULL;
+#if !UBIDI_HARDCODE_DATA
+static UBiDiProps *gBdp=NULL;
+static UErrorCode gErrorCode=U_ZERO_ERROR;
+static int8_t gHaveData=0;
+#endif
+
+static UBool U_CALLCONV
+ubidi_cleanup(void) {
+ ubidi_closeProps(gBdpDummy);
+ gBdpDummy=NULL;
+#if !UBIDI_HARDCODE_DATA
+ ubidi_closeProps(gBdp);
+ gBdp=NULL;
+ gErrorCode=U_ZERO_ERROR;
+ gHaveData=0;
+#endif
+ return TRUE;
+}
+
+U_CFUNC const UBiDiProps *
+ubidi_getSingleton(UErrorCode *pErrorCode) {
+#if UBIDI_HARDCODE_DATA
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ return &ubidi_props_singleton;
+#else
+ int8_t haveData;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ UMTX_CHECK(NULL, gHaveData, haveData);
+
+ if(haveData>0) {
+ /* data was loaded */
+ return gBdp;
+ } else if(haveData<0) {
+ /* data loading failed */
+ *pErrorCode=gErrorCode;
+ return NULL;
+ } else /* haveData==0 */ {
+ /* load the data */
+ UBiDiProps *bdp=ubidi_openProps(pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ gHaveData=-1;
+ gErrorCode=*pErrorCode;
+ return NULL;
+ }
+
+ /* set the static variables */
+ umtx_lock(NULL);
+ if(gBdp==NULL) {
+ gBdp=bdp;
+ bdp=NULL;
+ gHaveData=1;
+ ucln_common_registerCleanup(UCLN_COMMON_UBIDI, ubidi_cleanup);
+ }
+ umtx_unlock(NULL);
+
+ ubidi_closeProps(bdp);
+ return gBdp;
+ }
+#endif
+}
+
+U_CAPI const UBiDiProps *
+ubidi_getDummy(UErrorCode *pErrorCode) {
+ UBiDiProps *bdp;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ UMTX_CHECK(NULL, gBdpDummy, bdp);
+
+ if(bdp!=NULL) {
+ /* the dummy object was already created */
+ return bdp;
+ } else /* bdp==NULL */ {
+ /* create the dummy object */
+ int32_t *indexes;
+
+ bdp=(UBiDiProps *)uprv_malloc(sizeof(UBiDiProps)+UBIDI_IX_TOP*4+UTRIE_DUMMY_SIZE);
+ if(bdp==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memset(bdp, 0, sizeof(UBiDiProps)+UBIDI_IX_TOP*4);
+
+ bdp->indexes=indexes=(int32_t *)(bdp+1);
+ indexes[UBIDI_IX_INDEX_TOP]=UBIDI_IX_TOP;
+
+ indexes[UBIDI_IX_TRIE_SIZE]=
+ utrie_unserializeDummy(&bdp->trie, indexes+UBIDI_IX_TOP, UTRIE_DUMMY_SIZE, 0, 0, TRUE, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ uprv_free(bdp);
+ return NULL;
+ }
+
+ bdp->formatVersion[0]=1;
+ bdp->formatVersion[2]=UTRIE_SHIFT;
+ bdp->formatVersion[3]=UTRIE_INDEX_SHIFT;
+
+ /* set the static variables */
+ umtx_lock(NULL);
+ if(gBdpDummy==NULL) {
+ gBdpDummy=bdp;
+ bdp=NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_UBIDI, ubidi_cleanup);
+ }
+ umtx_unlock(NULL);
+
+ uprv_free(bdp);
+ return gBdpDummy;
+ }
+}
+
+/* set of property starts for UnicodeSet ------------------------------------ */
+
+static UBool U_CALLCONV
+_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+ /* add the start code point to the USet */
+ const USetAdder *sa=(const USetAdder *)context;
+ sa->add(sa->set, start);
+ return TRUE;
+}
+
+U_CFUNC void
+ubidi_addPropertyStarts(const UBiDiProps *bdp, const USetAdder *sa, UErrorCode *pErrorCode) {
+ int32_t i, length;
+ UChar32 c, start, limit;
+
+ const uint8_t *jgArray;
+ uint8_t prev, jg;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ /* add the start code point of each same-value range of the trie */
+ utrie_enum(&bdp->trie, NULL, _enumPropertyStartsRange, sa);
+
+ /* add the code points from the bidi mirroring table */
+ length=bdp->indexes[UBIDI_IX_MIRROR_LENGTH];
+ for(i=0; imirrors[i]);
+ sa->addRange(sa->set, c, c+1);
+ }
+
+ /* add the code points from the Joining_Group array where the value changes */
+ start=bdp->indexes[UBIDI_IX_JG_START];
+ limit=bdp->indexes[UBIDI_IX_JG_LIMIT];
+ jgArray=bdp->jgArray;
+ prev=0;
+ while(startadd(sa->set, start);
+ prev=jg;
+ }
+ ++start;
+ }
+ if(prev!=0) {
+ /* add the limit code point if the last value was not 0 (it is now start==limit) */
+ sa->add(sa->set, limit);
+ }
+
+ /* add code points with hardcoded properties, plus the ones following them */
+
+ /* (none right now) */
+}
+
+/* data access primitives --------------------------------------------------- */
+
+/* UTRIE_GET16() itself validates c */
+#define GET_PROPS(bdp, c, result) \
+ UTRIE_GET16(&(bdp)->trie, c, result);
+
+/* property access functions ------------------------------------------------ */
+
+U_CFUNC int32_t
+ubidi_getMaxValue(const UBiDiProps *bdp, UProperty which) {
+ int32_t max;
+
+ if(bdp==NULL) {
+ return -1;
+ }
+
+ max=bdp->indexes[UBIDI_MAX_VALUES_INDEX];
+ switch(which) {
+ case UCHAR_BIDI_CLASS:
+ return (max&UBIDI_CLASS_MASK);
+ case UCHAR_JOINING_GROUP:
+ return (max&UBIDI_MAX_JG_MASK)>>UBIDI_MAX_JG_SHIFT;
+ case UCHAR_JOINING_TYPE:
+ return (max&UBIDI_JT_MASK)>>UBIDI_JT_SHIFT;
+ default:
+ return -1; /* undefined */
+ }
+}
+
+U_CAPI UCharDirection
+ubidi_getClass(const UBiDiProps *bdp, UChar32 c) {
+ uint32_t props;
+ GET_PROPS(bdp, c, props);
+ return (UCharDirection)UBIDI_GET_CLASS(props);
+}
+
+U_CFUNC UBool
+ubidi_isMirrored(const UBiDiProps *bdp, UChar32 c) {
+ uint32_t props;
+ GET_PROPS(bdp, c, props);
+ return (UBool)UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
+}
+
+U_CFUNC UChar32
+ubidi_getMirror(const UBiDiProps *bdp, UChar32 c) {
+ uint32_t props;
+ int32_t delta;
+
+ GET_PROPS(bdp, c, props);
+ delta=((int16_t)props)>>UBIDI_MIRROR_DELTA_SHIFT;
+ if(delta!=UBIDI_ESC_MIRROR_DELTA) {
+ return c+delta;
+ } else {
+ /* look for mirror code point in the mirrors[] table */
+ const uint32_t *mirrors;
+ uint32_t m;
+ int32_t i, length;
+ UChar32 c2;
+
+ mirrors=bdp->mirrors;
+ length=bdp->indexes[UBIDI_IX_MIRROR_LENGTH];
+
+ /* linear search */
+ for(i=0; i>UBIDI_JT_SHIFT);
+}
+
+U_CFUNC UJoiningGroup
+ubidi_getJoiningGroup(const UBiDiProps *bdp, UChar32 c) {
+ UChar32 start, limit;
+
+ start=bdp->indexes[UBIDI_IX_JG_START];
+ limit=bdp->indexes[UBIDI_IX_JG_LIMIT];
+ if(start<=c && cjgArray[c-start];
+ } else {
+ return U_JG_NO_JOINING_GROUP;
+ }
+}
+
+/* public API (see uchar.h) ------------------------------------------------- */
+
+U_CFUNC UCharDirection
+u_charDirection(UChar32 c) {
+ UErrorCode errorCode=U_ZERO_ERROR;
+ const UBiDiProps *bdp=ubidi_getSingleton(&errorCode);
+ if(bdp!=NULL) {
+ return ubidi_getClass(bdp, c);
+ } else {
+ return U_LEFT_TO_RIGHT;
+ }
+}
+
+U_CFUNC UBool
+u_isMirrored(UChar32 c) {
+ UErrorCode errorCode=U_ZERO_ERROR;
+ const UBiDiProps *bdp=ubidi_getSingleton(&errorCode);
+ return (UBool)(bdp!=NULL && ubidi_isMirrored(bdp, c));
+}
+
+U_CFUNC UChar32
+u_charMirror(UChar32 c) {
+ UErrorCode errorCode=U_ZERO_ERROR;
+ const UBiDiProps *bdp=ubidi_getSingleton(&errorCode);
+ if(bdp!=NULL) {
+ return ubidi_getMirror(bdp, c);
+ } else {
+ return c;
+ }
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidi_props.h b/Build/source/libs/icu/icu-xetex/common/ubidi_props.h
new file mode 100644
index 00000000000..d6da311f9e5
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidi_props.h
@@ -0,0 +1,160 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2004-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: ubidi_props.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004dec30
+* created by: Markus W. Scherer
+*
+* Low-level Unicode bidi/shaping properties access.
+*/
+
+#ifndef __UBIDI_PROPS_H__
+#define __UBIDI_PROPS_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "uset_imp.h"
+#include "udataswp.h"
+
+U_CDECL_BEGIN
+
+/* library API -------------------------------------------------------------- */
+
+struct UBiDiProps;
+typedef struct UBiDiProps UBiDiProps;
+
+U_CFUNC UBiDiProps *
+ubidi_openProps(UErrorCode *pErrorCode);
+
+U_CFUNC UBiDiProps *
+ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode);
+
+U_CFUNC void
+ubidi_closeProps(UBiDiProps *bdp);
+
+
+U_CFUNC const UBiDiProps *
+ubidi_getSingleton(UErrorCode *pErrorCode);
+
+/**
+ * Get a singleton dummy object, one that works with no real data.
+ * This can be used when the real data is not available.
+ * Using the dummy can reduce checks for available data after an initial failure.
+ */
+U_CAPI const UBiDiProps *
+ubidi_getDummy(UErrorCode *pErrorCode);
+
+
+U_CAPI int32_t
+ubidi_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void
+ubidi_addPropertyStarts(const UBiDiProps *bdp, const USetAdder *sa, UErrorCode *pErrorCode);
+
+/* property access functions */
+
+U_CFUNC int32_t
+ubidi_getMaxValue(const UBiDiProps *bdp, UProperty which);
+
+U_CAPI UCharDirection
+ubidi_getClass(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UBool
+ubidi_isMirrored(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UChar32
+ubidi_getMirror(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UBool
+ubidi_isBidiControl(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UBool
+ubidi_isJoinControl(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UJoiningType
+ubidi_getJoiningType(const UBiDiProps *bdp, UChar32 c);
+
+U_CFUNC UJoiningGroup
+ubidi_getJoiningGroup(const UBiDiProps *bdp, UChar32 c);
+
+/* file definitions --------------------------------------------------------- */
+
+#define UBIDI_DATA_NAME "ubidi"
+#define UBIDI_DATA_TYPE "icu"
+
+/* format "BiDi" */
+#define UBIDI_FMT_0 0x42
+#define UBIDI_FMT_1 0x69
+#define UBIDI_FMT_2 0x44
+#define UBIDI_FMT_3 0x69
+
+/* indexes into indexes[] */
+enum {
+ UBIDI_IX_INDEX_TOP,
+ UBIDI_IX_LENGTH,
+ UBIDI_IX_TRIE_SIZE,
+ UBIDI_IX_MIRROR_LENGTH,
+
+ UBIDI_IX_JG_START,
+ UBIDI_IX_JG_LIMIT,
+
+ UBIDI_MAX_VALUES_INDEX=15,
+ UBIDI_IX_TOP=16
+};
+
+/* definitions for 16-bit bidi/shaping properties word ---------------------- */
+
+enum {
+ /* UBIDI_CLASS_SHIFT=0, */ /* bidi class: 5 bits (4..0) */
+ UBIDI_JT_SHIFT=5, /* joining type: 3 bits (7..5) */
+
+ /* UBIDI__SHIFT=8, reserved: 2 bits (9..8) */
+
+ UBIDI_JOIN_CONTROL_SHIFT=10,
+ UBIDI_BIDI_CONTROL_SHIFT=11,
+
+ UBIDI_IS_MIRRORED_SHIFT=12, /* 'is mirrored' */
+ UBIDI_MIRROR_DELTA_SHIFT=13, /* bidi mirroring delta: 3 bits (15..13) */
+
+ UBIDI_MAX_JG_SHIFT=16 /* max JG value in indexes[UBIDI_MAX_VALUES_INDEX] bits 23..16 */
+};
+
+#define UBIDI_CLASS_MASK 0x0000001f
+#define UBIDI_JT_MASK 0x000000e0
+
+#define UBIDI_MAX_JG_MASK 0x00ff0000
+
+#define UBIDI_GET_CLASS(props) ((props)&UBIDI_CLASS_MASK)
+#define UBIDI_GET_FLAG(props, shift) (((props)>>(shift))&1)
+
+enum {
+ UBIDI_ESC_MIRROR_DELTA=-4,
+ UBIDI_MIN_MIRROR_DELTA=-3,
+ UBIDI_MAX_MIRROR_DELTA=3
+};
+
+/* definitions for 32-bit mirror table entry -------------------------------- */
+
+enum {
+ /* the source Unicode code point takes 21 bits (20..0) */
+ UBIDI_MIRROR_INDEX_SHIFT=21,
+ UBIDI_MAX_MIRROR_INDEX=0x7ff
+};
+
+#define UBIDI_GET_MIRROR_CODE_POINT(m) (UChar32)((m)&0x1fffff)
+
+#define UBIDI_GET_MIRROR_INDEX(m) ((m)>>UBIDI_MIRROR_INDEX_SHIFT)
+
+U_CDECL_END
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidi_props_data.c b/Build/source/libs/icu/icu-xetex/common/ubidi_props_data.c
new file mode 100644
index 00000000000..ea30b7e0cde
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidi_props_data.c
@@ -0,0 +1,549 @@
+/*
+ * Copyright (C) 1999-2007, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *
+ * file name: ubidi_props_data.c
+ *
+ * machine-generated on: 2007-08-15
+ */
+
+static const UVersionInfo ubidi_props_dataVersion={5,0,0,0};
+
+static const int32_t ubidi_props_indexes[UBIDI_IX_TOP]={0x10,0x3f04,0x3d10,0x1a,0x622,0x76e,0,0,0,0,0,0,0,0,0,0x3500b2};
+
+static const uint16_t ubidi_props_trieIndex[7808]={
+0x250,0x258,0x260,0x268,0x270,0x278,0x280,0x288,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x28e,0x296,0x29e,0x2a6,0x2a6,0x2a6,0x2aa,0x2b2,0x248,0x248,0x2b5,
+0x248,0x248,0x248,0x248,0x2bd,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x2c3,0x2c8,0x2d0,0x2d2,
+0x2da,0x2e2,0x2ea,0x2f2,0x2f8,0x2ff,0x307,0x30f,0x317,0x31f,0x325,0x32c,0x330,0x337,0x33f,0x345,
+0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x34d,0x34e,0x356,0x35e,0x366,0x34e,0x36e,0x376,
+0x34d,0x34e,0x37e,0x382,0x34d,0x34e,0x38a,0x392,0x366,0x397,0x39f,0x248,0x3a4,0x248,0x3ac,0x3b0,
+0x248,0x3b7,0x3bf,0x248,0x248,0x3c5,0x3cd,0x3d5,0x248,0x248,0x3dd,0x248,0x248,0x248,0x3e3,0x248,
+0x248,0x3e9,0x3f1,0x248,0x248,0x3f5,0x3fd,0x248,0x401,0x408,0x248,0x410,0x418,0x41f,0x3a3,0x248,
+0x248,0x427,0x401,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x42e,0x248,0x436,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x43e,0x248,0x248,0x248,0x446,0x446,0x372,0x372,0x248,0x44c,0x454,0x436,
+0x45c,0x248,0x248,0x248,0x248,0x364,0x248,0x248,0x248,0x464,0x46c,0x248,0x248,0x248,0x46e,0x476,
+0x47e,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x486,0x489,0x3a4,0x491,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x499,0x3b7,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x49c,0x4a4,0x4a8,
+0x4b0,0x4b6,0x4bd,0x4c5,0x4cd,0x4d5,0x4db,0x4df,0x4e7,0x4ef,0x4f7,0x248,0x4ff,0x476,0x476,0x476,
+0x507,0x50f,0x517,0x51f,0x524,0x52c,0x534,0x53a,0x542,0x54a,0x248,0x550,0x557,0x476,0x476,0x55d,
+0x476,0x565,0x56d,0x476,0x575,0x248,0x248,0x473,0x476,0x476,0x476,0x476,0x476,0x476,0x476,0x476,
+0x476,0x476,0x476,0x476,0x57d,0x585,0x248,0x248,0x58d,0x593,0x598,0x5a0,0x57f,0x5a6,0x5ae,0x5b6,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x476,0x476,0x476,0x476,0x5be,0x5c5,0x5cd,0x5d5,
+0x5dd,0x5e5,0x5ed,0x5f4,0x5fc,0x604,0x60b,0x613,0x61b,0x623,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x62a,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x632,0x248,0x248,0x248,0x63a,0x476,0x476,0x479,0x476,0x476,0x476,0x476,0x476,0x476,0x641,0x647,
+0x64f,0x657,0x248,0x248,0x65f,0x666,0x248,0x287,0x248,0x248,0x248,0x248,0x248,0x248,0x47a,0x248,
+0x667,0x248,0x4ff,0x66f,0x248,0x677,0x67f,0x248,0x248,0x248,0x248,0x683,0x248,0x248,0x46e,0x286,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x476,0x476,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x4ff,0x476,0x565,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x61b,0x46d,0x248,0x248,0x248,0x248,0x248,0x248,
+0x68b,0x692,0x248,0x695,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x785,0x788,0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,
+0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,0x248,0x790,0x798,0x790,0x248,0x790,0x248,0x790,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x69b,0x6a3,0x6a7,0x330,0x330,0x330,0x330,0x330,
+0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x6ab,0x330,0x330,0x330,0x330,0x6b3,0x6b7,
+0x6bf,0x6c7,0x6cb,0x6d3,0x330,0x330,0x330,0x6d7,0x6df,0x260,0x6e7,0x6ef,0x248,0x248,0x248,0x6f7,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x6ff,0x248,0x476,0x476,0x56d,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x707,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,
+0x70f,0x713,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,
+0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,
+0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,0x2d2,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x71b,0x723,0x729,0x248,0x248,
+0x476,0x476,0x731,0x248,0x248,0x248,0x248,0x248,0x476,0x476,0x739,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x73f,0x248,0x746,0x248,0x742,0x248,0x749,0x248,0x751,0x755,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,
+0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x248,0x75d,
+0x765,0x76d,0x76d,0x76d,0x775,0x775,0x775,0x775,0x2a6,0x2a6,0x2a6,0x2a6,0x2a6,0x2a6,0x2a6,0x77d,
+0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,
+0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,
+0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,0x775,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,8,7,8,9,7,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,7,7,7,8,
+9,0xa,0xa,4,4,4,0xa,0xa,0x300a,0xf00a,0xa,3,6,3,6,6,
+2,2,2,2,2,2,2,2,2,2,6,0xa,0x500a,0xa,0xd00a,0xa,
+0xa,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0x500a,0xa,0xd00a,0xa,0xa,
+0xa,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0x500a,0xa,0xd00a,0xa,0x12,
+0x12,0x12,0x12,0x12,0x12,7,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+6,0xa,4,4,4,4,0xa,0xa,0xa,0xa,0,0x900a,0xa,0xb2,0xa,0xa,
+4,4,2,2,0xa,0,0xa,0xa,0xa,2,0,0x900a,0xa,0xa,0xa,0xa,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0xa,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0xa,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0xa,0xa,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,0,0,0xa,0xa,0,0,
+0,0,0,0,0,0,0xa,0,0,0,0,0,0xa,0xa,0,0xa,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0,0xb1,0xb1,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0xa,0,0,0,0,0,1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,1,0xb1,
+1,0xb1,0xb1,1,0xb1,0xb1,1,0xb1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,6,0xd,0xa,0xa,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0x8d,0x8d,0x8d,0x8d,0x4d,0x8d,
+0x4d,0x8d,0x4d,0x4d,0x4d,0x4d,0x4d,0x8d,0x8d,0x8d,0x8d,0x4d,0x4d,0x4d,0x4d,0x4d,
+0x4d,0x4d,0x4d,0xd,0xd,0xd,0xd,0xd,0x2d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,
+0x8d,0x4d,0x4d,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xd,5,5,5,5,5,5,5,5,
+5,5,4,5,5,0xd,0x4d,0x4d,0xb1,0x8d,0x8d,0x8d,0xd,0x8d,0x8d,0x8d,
+0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,
+0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,
+0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,
+0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x8d,0x4d,0x4d,0x8d,
+0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x8d,0x4d,0x8d,0x4d,0x8d,0x4d,0x4d,0x8d,0x8d,
+0xd,0x8d,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xd,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xd,0xd,0xb1,0xb1,0xa,0xb1,0xb1,0xb1,0xb1,0x8d,0x8d,2,2,2,2,
+2,2,2,2,2,2,0x4d,0x4d,0x4d,0xd,0xd,0x4d,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xb2,0x8d,0xb1,0x4d,0x4d,
+0x4d,0x8d,0x8d,0x8d,0x8d,0x8d,0x4d,0x4d,0x4d,0x4d,0x8d,0x4d,0x4d,0x4d,0x4d,0x4d,
+0x4d,0x4d,0x4d,0x4d,0x8d,0x4d,0x8d,0x4d,0x8d,0x4d,0x4d,0x8d,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xd,
+0xd,0x8d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x8d,0x8d,0x8d,
+0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x4d,0x8d,0x8d,0x4d,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,
+0xd,0xd,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,1,1,1,1,
+1,1,1,1,1,1,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
+0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,1,1,0xa,0xa,0xa,0xa,0x21,1,
+1,1,1,1,0,0xb1,0xb1,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xb1,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0,0,0,0,0xb1,0,0,0,0xb1,0xb1,0xb1,0xb1,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xb1,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0,0,0,
+0,0,0,0,0,0xb1,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,4,4,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,0xb1,
+0xb1,0,0,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0,0xb1,
+0xb1,0,0,0,0,0xb1,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,
+0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xb1,0,0,0xb1,0,0xb1,0xb1,0xb1,
+0,0,0,0,0,0,0,0,0,0xb1,0,0,0,0,0,0,
+0,0,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0xb1,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,4,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0,0,0,
+0,0,0xb1,0xb1,0xb1,0,0xb1,0xb1,0xb1,0xb1,0,0,0,0,0,0,
+0,0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xb1,0,0,0xa0,0,0,0,0,0,0,0xa0,0,0,0,0,0,
+0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0xb1,0xb1,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xa,0xa,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,
+0,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0xb1,0,0,0,0,0,0,0,0xb1,0xb1,
+0xb1,0,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xb1,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,
+0,0,0,4,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xb1,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0xb1,
+0xb1,0,0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xb1,0,0xb1,0,0xb1,0x300a,0xf00a,0x300a,0xf00a,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,
+0xb1,0xb1,0xb1,0xb1,0xb1,0,0xb1,0xb1,0,0,0,0,0,0,0,0,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0,0xb1,0,
+0,0,0xb1,0xb1,0,0xb1,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0xb1,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0,0,0,0,0,0,9,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0x300a,0xf00a,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa0,0xa0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,
+0,0,0,0,0,0,0xb1,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,4,0,0xb1,0,0,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xb1,0xb1,0xb1,9,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xb1,0xb1,0xb1,0,0,0,0,0xb1,0xb1,0x11,0x11,0x11,0,0,0,0,
+0,0,0xb1,0,0,0,0,0,0,0xb1,0xb1,0xb1,0,0,0,0,
+0xa,0,0,0,0xa,0xa,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xb1,
+0xb1,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xb1,0,0xb1,0xb1,0xb1,0xb1,0xb1,0,
+0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,
+0,0,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xa,0,0xa,
+0xa,0xa,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0,
+9,9,9,9,9,9,9,9,9,9,9,0xb2,0x412,0x432,0x8a0,0x8a1,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+9,7,0x8ab,0x8ae,0x8b0,0x8ac,0x8af,6,4,4,4,4,4,0xa,0xa,0xa,
+0xa,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,6,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,9,0xb2,0xb2,0xb2,0xb2,0x12,0x12,0x12,0x12,0x12,0x12,0xb2,0xb2,
+0xb2,0xb2,0xb2,0xb2,2,0,0,0,2,2,2,2,2,2,3,3,
+0xa,0x300a,0xf00a,0,2,2,2,2,2,2,2,2,2,2,3,3,
+0xa,0x300a,0xf00a,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,
+4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0,0xa,
+0xa,0xa,0xa,0,0xa,0xa,0,0,0,0,0,0,0,0,0,0,
+0xa,0,0xa,0xa,0xa,0,0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,
+0,0xa,0,0xa,0,0xa,0,0,0,0,4,0,0,0,0,0,
+0,0,0,0,0,0,0xa,0xa,0,0,0,0,0x100a,0xa,0xa,0xa,
+0xa,0,0,0,0,0,0xa,0xa,0xa,0xa,0,0,0,0,0,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,0x100a,
+0x100a,0xa,0xa,0xa,0x700a,0x700a,0x700a,0xb00a,0xb00a,0xb00a,0xa,0xa,0xa,0x100a,3,4,
+0xa,0x900a,0x100a,0xa,0xa,0xa,0x100a,0x100a,0x100a,0x100a,0xa,0x100a,0x100a,0x100a,0x100a,0xa,
+0x100a,0xa,0x100a,0xa,0xa,0xa,0xa,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,
+0xa,0xa,0xa,0xa,0xa,0x100a,0xa,0x100a,0x300a,0xf00a,0x100a,0x100a,0x100a,0x100a,0x100a,0x900a,
+0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,
+0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,0xa,0x100a,0xa,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x100a,0xa,0xa,0x300a,
+0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0x900a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0x300a,0xf00a,0xa,0xa,0x900a,0x100a,0x900a,0x900a,0x100a,0x900a,0x100a,0x100a,0x100a,0x100a,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x100a,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x900a,0xa,0xa,
+0x300a,0xf00a,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,0x300a,0xf00a,0x900a,0x900a,0x900a,0x100a,0x900a,0x900a,
+0x100a,0x100a,0x900a,0x900a,0x900a,0x900a,0x900a,0x100a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xa,0xa,0xa,0xa,0,0xa,0xa,0xa,0xa,0,0,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0xa,0,0xa,
+0xa,0xa,0xa,0,0,0,0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,
+0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0x100a,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0xa,
+0xa,0xa,0xa,0,0,0,0,0,0xa,0xa,0xa,0x100a,0x100a,0x300a,0xf00a,0xa,
+0xa,0xa,0xa,0xa,0x100a,0x300a,0xf00a,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,
+0x300a,0xf00a,0x300a,0xf00a,0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,
+0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x700a,0x300a,0xf00a,0xb00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,
+0xf00a,0xa,0xa,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,
+0x100a,0x100a,0x100a,0x100a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x900a,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0x300a,0xf00a,0x100a,0x100a,0x300a,0xf00a,0xa,0xa,0xa,0x100a,0xa,0xa,
+0xa,0xa,0x100a,0x300a,0xf00a,0x300a,0xf00a,0xa,0x300a,0xf00a,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,
+0x100a,0xa,0xa,0xa,0xa,0x100a,0xa,0x100a,0x100a,0x100a,0xa,0xa,0x100a,0x100a,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x900a,0x100a,0x100a,0x300a,0xf00a,0xa,0xa,
+0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,
+0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,
+0x100a,0xa,0x100a,0x100a,0x100a,0x100a,0xa,0xa,0x100a,0xa,0x100a,0xa,0xa,0x100a,0xa,0x300a,
+0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,
+0x300a,0xf00a,0x100a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x100a,0x100a,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0x300a,0xf00a,0xa,0xa,0xa,0xa,0x100a,0x100a,0x100a,0x100a,0xa,0x100a,
+0x100a,0xa,0xa,0x100a,0x100a,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x100a,0x100a,0x300a,0xf00a,0x300a,
+0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x300a,0xf00a,0x100a,0x100a,0x100a,
+0x100a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x100a,0x100a,0x100a,
+0x100a,0x300a,0xf00a,0x100a,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0x300a,
+0xf00a,0x100a,0x100a,0x300a,0xf00a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x300a,0xf00a,0x300a,0xf00a,0x300a,
+0xf00a,0x300a,0xf00a,0x100a,0x100a,0x100a,0x100a,0x100a,0x100a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,
+0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0x100a,0xa,0x900a,0xa,0xa,0xa,0x100a,0x900a,
+0x900a,0x900a,0x100a,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x100a,0xa,0xa,0xa,0xa,0x100a,
+0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x100a,0xa,0x100a,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0xa,0xa,0xa,0xa,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,
+0xa,0xa,0xa,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,
+0xa,0x300a,0xf00a,0xa,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0,0,0,0,0x300a,0xf00a,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,9,0xa,0xa,0xa,
+0xa,0,0,0,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,
+0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,0xa,0xa,0xa,0xa,0xa,0,0,0,
+0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xa,0,0,0,
+0,0,0xa,0xa,0,0,0,0,0,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0xb1,0xb1,0xa,0xa,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0xa,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xa,0xa,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0xa,0xa,0xa,0xa,0,0,0,0,0,0,0,0x11,0,
+0,0,0xb1,0,0,0,0,0xb1,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,0,
+0xa,0xa,0xa,0xa,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,1,0xb1,1,1,1,1,1,
+1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xa,0xa,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xa,0xd,0xd,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,0,0xb1,0xb1,0xb1,0xb1,
+0,0,0,0,0,0,0,0,0,0,0,0,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,6,0xa,6,0,
+0xa,6,0xa,0xa,0xa,0x300a,0xf00a,0x300a,0xf00a,0x300a,0xf00a,4,0xa,0xa,3,3,
+0x300a,0xf00a,0xa,0,0xa,4,4,0xa,0,0,0,0,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xd,0xb2,0,0xa,0xa,4,
+4,4,0xa,0xa,0x300a,0xf00a,0xa,3,6,3,6,6,2,2,2,2,
+2,2,2,2,2,2,6,0xa,0x500a,0xa,0xd00a,0xa,0xa,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0x500a,0xa,0xd00a,0xa,0x300a,0xf00a,0xa,0x300a,0xf00a,
+0xa,0xa,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,4,4,0xa,0xa,
+0xa,4,4,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0xaa,0xaa,0xaa,0xa,0xa,0x12,0x12,0,0xa,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,0xa,1,0xb1,0xb1,0xb1,
+1,0xb1,0xb1,1,1,1,1,1,0xb1,0xb1,0xb1,0xb1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,0xb1,0xb1,0xb1,1,1,1,1,0xb1,0,0,0,0,
+0,0,0,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,0,0xb2,
+0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,
+0,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xb1,0xb1,
+0xb1,0xb1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa,0xa,0xb1,0xb1,0xb1,0xa,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,
+0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0x1000,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0x1000,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0x1000,0,0,0,0,0,0,0,0,
+0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0x12,0x12,0x12,0xb2,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,
+0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,
+0xb2,0xb2,0xb2,0xb2,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0xb1,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x820,0,0x840,0x860,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0x880,0x8a0,0,0,0,0,0,0,0,0,0,0x8c0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x8c0,
+0x8e0,0x900,0x900,0x900,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
+
+static const uint32_t ubidi_props_mirrors[26]={
+0x2000ab,0xbb,0x2a02215,0x1202243,0x2802298,0x2c022a6,0x30022a8,0x2e022a9,0x32022ab,0x6022cd,0x1e022f2,0x20022f3,0x22022f4,0x24022f6,0x26022f7,0x14022fa,
+0x16022fb,0x18022fc,0x1a022fd,0x1c022fe,0x8029b8,0x4029f5,0xa02ade,0xe02ae3,0xc02ae4,0x1002ae5
+};
+
+static const uint8_t ubidi_props_jgArray[332]={
+3,3,0x2c,3,0x2d,3,4,0x2a,4,4,0xd,0xd,0xd,6,6,0x1f,
+0x1f,0x23,0x23,0x21,0x21,0x28,0x28,1,1,0,0,0,0,0,0,9,
+0x1d,0x13,0x16,0x18,0x1a,0x10,0x2c,0x2d,0x2d,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,4,0x1d,0,3,
+3,3,0,3,0x2c,0x2c,0x2d,4,4,4,4,4,4,4,4,0xd,
+0xd,0xd,0xd,0xd,0xd,0xd,6,6,6,6,6,6,6,6,6,0x1f,
+0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x23,0x23,0x23,0x21,0x21,0x28,1,9,
+9,9,9,9,9,0x1d,0x1d,0xb,0x26,0xb,0x13,0x13,0x13,0xb,0xb,0xb,
+0xb,0xb,0xb,0x16,0x16,0x16,0x16,0x1a,0x1a,0x1a,0x1a,0x1a,0x15,0xd,0x2a,0x11,
+0x11,0xe,0x2c,0x2c,0x2c,0x2c,0x2c,0x2c,0x2c,0x2c,0x2d,0x2f,0x2d,0x2c,0x2d,0x2d,
+0x2e,0x2e,0,0x2a,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,6,0x1f,0,0,
+0,0,0,0,0,0,0,0,0x23,0x21,1,0,0,0x15,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,
+5,0xc,0xc,7,7,0xf,0x27,0x32,0x12,0x2b,0x2b,0x30,0x31,0x14,0x17,0x19,
+0x1b,0x24,0xa,8,0x1c,0x20,0x22,0x1e,7,0x25,0x29,5,0xc,7,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0x35,0x34,0x33,4,4,
+4,4,4,4,4,0xd,0xd,6,6,0x1f,0x23,1,1,1,9,9,
+0xb,0xb,0xb,0x18,0x18,0x1a,0x1a,0x1a,0x16,0x1f,0x1f,0x23
+};
+
+static const UBiDiProps ubidi_props_singleton={
+ NULL,
+ ubidi_props_indexes,
+ ubidi_props_mirrors,
+ ubidi_props_jgArray,
+ {
+ ubidi_props_trieIndex,
+ NULL,
+ utrie_defaultGetFoldingOffset,
+ 2336,
+ 5472,
+ 0,
+ TRUE
+ },
+ { 1,0,5,2 }
+};
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidiimp.h b/Build/source/libs/icu/icu-xetex/common/ubidiimp.h
new file mode 100644
index 00000000000..1f1dcaa04f7
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidiimp.h
@@ -0,0 +1,385 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ubidiimp.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 1999aug06
+* created by: Markus W. Scherer, updated by Matitiahu Allouche
+*/
+
+#ifndef UBIDIIMP_H
+#define UBIDIIMP_H
+
+/* set import/export definitions */
+#ifdef U_COMMON_IMPLEMENTATION
+
+#include "unicode/utypes.h"
+#include "unicode/uchar.h"
+#include "ubidi_props.h"
+
+/* miscellaneous definitions ---------------------------------------------- */
+
+typedef uint8_t DirProp;
+typedef uint32_t Flags;
+
+/* Comparing the description of the BiDi algorithm with this implementation
+ is easier with the same names for the BiDi types in the code as there.
+ See UCharDirection in uchar.h .
+*/
+enum {
+ L= U_LEFT_TO_RIGHT,
+ R= U_RIGHT_TO_LEFT,
+ EN= U_EUROPEAN_NUMBER,
+ ES= U_EUROPEAN_NUMBER_SEPARATOR,
+ ET= U_EUROPEAN_NUMBER_TERMINATOR,
+ AN= U_ARABIC_NUMBER,
+ CS= U_COMMON_NUMBER_SEPARATOR,
+ B= U_BLOCK_SEPARATOR,
+ S= U_SEGMENT_SEPARATOR,
+ WS= U_WHITE_SPACE_NEUTRAL,
+ ON= U_OTHER_NEUTRAL,
+ LRE=U_LEFT_TO_RIGHT_EMBEDDING,
+ LRO=U_LEFT_TO_RIGHT_OVERRIDE,
+ AL= U_RIGHT_TO_LEFT_ARABIC,
+ RLE=U_RIGHT_TO_LEFT_EMBEDDING,
+ RLO=U_RIGHT_TO_LEFT_OVERRIDE,
+ PDF=U_POP_DIRECTIONAL_FORMAT,
+ NSM=U_DIR_NON_SPACING_MARK,
+ BN= U_BOUNDARY_NEUTRAL,
+ dirPropCount
+};
+
+/*
+ * Sometimes, bit values are more appropriate
+ * to deal with directionality properties.
+ * Abbreviations in these macro names refer to names
+ * used in the BiDi algorithm.
+ */
+#define DIRPROP_FLAG(dir) (1UL<<(dir))
+
+/* special flag for multiple runs from explicit embedding codes */
+#define DIRPROP_FLAG_MULTI_RUNS (1UL<<31)
+
+/* are there any characters that are LTR or RTL? */
+#define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
+#define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
+#define MASK_R_AL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL))
+
+/* explicit embedding codes */
+#define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
+#define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
+#define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO))
+
+#define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF))
+#define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT)
+
+/* paragraph and segment separators */
+#define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S))
+
+/* all types that are counted as White Space or Neutral in some steps */
+#define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT)
+#define MASK_N (DIRPROP_FLAG(ON)|MASK_WS)
+
+/* all types that are included in a sequence of European Terminators for (W5) */
+#define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT)
+
+/* types that are neutrals or could becomes neutrals in (Wn) */
+#define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N)
+
+/*
+ * These types may be changed to "e",
+ * the embedding type (L or R) of the run,
+ * in the BiDi algorithm (N2)
+ */
+#define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N)
+
+/* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */
+#define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1))
+
+#define IS_DEFAULT_LEVEL(level) ((level)>=0xfe)
+
+/*
+ * The following bit is ORed to the property of characters in paragraphs
+ * with contextual RTL direction when paraLevel is contextual.
+ */
+#define CONTEXT_RTL 0x80
+#define NO_CONTEXT_RTL(dir) ((dir)&~CONTEXT_RTL)
+/*
+ * The following is a variant of DIRPROP_FLAG which ignores the CONTEXT_RTL bit.
+ */
+#define DIRPROP_FLAG_NC(dir) (1UL<<(NO_CONTEXT_RTL(dir)))
+
+#define GET_PARALEVEL(ubidi, index) \
+ (UBiDiLevel)((ubidi)->defaultParaLevel ? (ubidi)->dirProps[index]>>7 \
+ : (ubidi)->paraLevel)
+
+/* Paragraph type for multiple paragraph support ---------------------------- */
+typedef int32_t Para;
+
+#define CR 0x000D
+#define LF 0x000A
+
+/* Run structure for reordering --------------------------------------------- */
+enum {
+ LRM_BEFORE=1,
+ LRM_AFTER=2,
+ RLM_BEFORE=4,
+ RLM_AFTER=8
+};
+
+typedef struct Run {
+ int32_t logicalStart, /* first character of the run; b31 indicates even/odd level */
+ visualLimit, /* last visual position of the run +1 */
+ insertRemove; /* if >0, flags for inserting LRM/RLM before/after run,
+ if <0, count of bidi controls within run */
+} Run;
+
+/* in a Run, logicalStart will get this bit set if the run level is odd */
+#define INDEX_ODD_BIT (1UL<<31)
+
+#define MAKE_INDEX_ODD_PAIR(index, level) ((index)|((int32_t)(level)<<31))
+#define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((int32_t)(level)<<31))
+#define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT)
+
+#define GET_INDEX(x) ((x)&~INDEX_ODD_BIT)
+#define GET_ODD_BIT(x) ((uint32_t)(x)>>31)
+#define IS_ODD_RUN(x) ((UBool)(((x)&INDEX_ODD_BIT)!=0))
+#define IS_EVEN_RUN(x) ((UBool)(((x)&INDEX_ODD_BIT)==0))
+
+U_CFUNC UBool
+ubidi_getRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
+
+/** BiDi control code points */
+enum {
+ ZWNJ_CHAR=0x200c,
+ ZWJ_CHAR,
+ LRM_CHAR,
+ RLM_CHAR,
+ LRE_CHAR=0x202a,
+ RLE_CHAR,
+ PDF_CHAR,
+ LRO_CHAR,
+ RLO_CHAR
+};
+
+#define IS_BIDI_CONTROL_CHAR(c) (((uint32_t)(c)&0xfffffffc)==ZWNJ_CHAR || (uint32_t)((c)-LRE_CHAR)<5)
+
+/* InsertPoints structure for noting where to put BiDi marks ---------------- */
+
+typedef struct Point {
+ int32_t pos; /* position in text */
+ int32_t flag; /* flag for LRM/RLM, before/after */
+} Point;
+
+typedef struct InsertPoints {
+ int32_t capacity; /* number of points allocated */
+ int32_t size; /* number of points used */
+ int32_t confirmed; /* number of points confirmed */
+ UErrorCode errorCode; /* for eventual memory shortage */
+ Point *points; /* pointer to array of points */
+} InsertPoints;
+
+
+/* UBiDi structure ----------------------------------------------------------- */
+
+struct UBiDi {
+ /* pointer to parent paragraph object (pointer to self if this object is
+ * a paragraph object); set to NULL in a newly opened object; set to a
+ * real value after a successful execution of ubidi_setPara or ubidi_setLine
+ */
+ const UBiDi * pParaBiDi;
+
+ const UBiDiProps *bdp;
+
+ /* alias pointer to the current text */
+ const UChar *text;
+
+ /* length of the current text */
+ int32_t originalLength;
+
+ /* if the UBIDI_OPTION_STREAMING option is set, this is the length
+ * of text actually processed by ubidi_setPara, which may be shorter than
+ * the original length.
+ * Otherwise, it is identical to the original length.
+ */
+ int32_t length;
+
+ /* if the UBIDI_OPTION_REMOVE_CONTROLS option is set, and/or
+ * marks are allowed to be inserted in one of the reordering mode, the
+ * length of the result string may be different from the processed length.
+ */
+ int32_t resultLength;
+
+ /* memory sizes in bytes */
+ int32_t dirPropsSize, levelsSize, parasSize, runsSize;
+
+ /* allocated memory */
+ DirProp *dirPropsMemory;
+ UBiDiLevel *levelsMemory;
+ Para *parasMemory;
+ Run *runsMemory;
+
+ /* indicators for whether memory may be allocated after ubidi_open() */
+ UBool mayAllocateText, mayAllocateRuns;
+
+ /* arrays with one value per text-character */
+ const DirProp *dirProps;
+ UBiDiLevel *levels;
+
+ /* are we performing an approximation of the "inverse BiDi" algorithm? */
+ UBool isInverse;
+
+ /* are we using the basic algorithm or its variation? */
+ UBiDiReorderingMode reorderingMode;
+
+ /* UBIDI_REORDER_xxx values must be ordered so that all the regular
+ * logical to visual modes come first, and all inverse BiDi modes
+ * come last.
+ */
+ #define UBIDI_REORDER_LAST_LOGICAL_TO_VISUAL UBIDI_REORDER_NUMBERS_SPECIAL
+
+ /* bitmask for reordering options */
+ uint32_t reorderingOptions;
+
+ /* must block separators receive level 0? */
+ UBool orderParagraphsLTR;
+
+ /* the paragraph level */
+ UBiDiLevel paraLevel;
+ /* original paraLevel when contextual */
+ /* must be one of UBIDI_DEFAULT_xxx or 0 if not contextual */
+ UBiDiLevel defaultParaLevel;
+
+ /* the following is set in ubidi_setPara, used in processPropertySeq */
+ const struct ImpTabPair * pImpTabPair; /* pointer to levels state table pair */
+
+ /* the overall paragraph or line directionality - see UBiDiDirection */
+ UBiDiDirection direction;
+
+ /* flags is a bit set for which directional properties are in the text */
+ Flags flags;
+
+ /* lastArabicPos is index to the last AL in the text, -1 if none */
+ int32_t lastArabicPos;
+
+ /* characters after trailingWSStart are WS and are */
+ /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */
+ int32_t trailingWSStart;
+
+ /* fields for paragraph handling */
+ int32_t paraCount; /* set in getDirProps() */
+ Para *paras; /* limits of paragraphs, filled in
+ ResolveExplicitLevels() or CheckExplicitLevels() */
+
+ /* for single paragraph text, we only need a tiny array of paras (no malloc()) */
+ Para simpleParas[1];
+
+ /* fields for line reordering */
+ int32_t runCount; /* ==-1: runs not set up yet */
+ Run *runs;
+
+ /* for non-mixed text, we only need a tiny array of runs (no malloc()) */
+ Run simpleRuns[1];
+
+ /* for inverse Bidi with insertion of directional marks */
+ InsertPoints insertPoints;
+
+ /* for option UBIDI_OPTION_REMOVE_CONTROLS */
+ int32_t controlCount;
+
+ /* for Bidi class callback */
+ UBiDiClassCallback *fnClassCallback; /* action pointer */
+ const void *coClassCallback; /* context pointer */
+};
+
+#define IS_VALID_PARA(x) ((x) && ((x)->pParaBiDi==(x)))
+#define IS_VALID_PARA_OR_LINE(x) ((x) && ((x)->pParaBiDi==(x) || (((x)->pParaBiDi) && (x)->pParaBiDi->pParaBiDi==(x)->pParaBiDi)))
+
+typedef union {
+ DirProp *dirPropsMemory;
+ UBiDiLevel *levelsMemory;
+ Para *parasMemory;
+ Run *runsMemory;
+} BidiMemoryForAllocation;
+
+/* Macros for initial checks at function entry */
+#define RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrcode, retvalue) \
+ if((pErrcode)==NULL || U_FAILURE(*pErrcode)) return retvalue
+#define RETURN_IF_NOT_VALID_PARA(bidi, errcode, retvalue) \
+ if(!IS_VALID_PARA(bidi)) { \
+ errcode=U_INVALID_STATE_ERROR; \
+ return retvalue; \
+ }
+#define RETURN_IF_NOT_VALID_PARA_OR_LINE(bidi, errcode, retvalue) \
+ if(!IS_VALID_PARA_OR_LINE(bidi)) { \
+ errcode=U_INVALID_STATE_ERROR; \
+ return retvalue; \
+ }
+#define RETURN_IF_BAD_RANGE(arg, start, limit, errcode, retvalue) \
+ if((arg)<(start) || (arg)>=(limit)) { \
+ (errcode)=U_ILLEGAL_ARGUMENT_ERROR; \
+ return retvalue; \
+ }
+
+#define RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrcode) \
+ if((pErrcode)==NULL || U_FAILURE(*pErrcode)) return
+#define RETURN_VOID_IF_NOT_VALID_PARA(bidi, errcode) \
+ if(!IS_VALID_PARA(bidi)) { \
+ errcode=U_INVALID_STATE_ERROR; \
+ return; \
+ }
+#define RETURN_VOID_IF_NOT_VALID_PARA_OR_LINE(bidi, errcode) \
+ if(!IS_VALID_PARA_OR_LINE(bidi)) { \
+ errcode=U_INVALID_STATE_ERROR; \
+ return; \
+ }
+#define RETURN_VOID_IF_BAD_RANGE(arg, start, limit, errcode) \
+ if((arg)<(start) || (arg)>=(limit)) { \
+ (errcode)=U_ILLEGAL_ARGUMENT_ERROR; \
+ return; \
+ }
+
+/* helper function to (re)allocate memory if allowed */
+U_CFUNC UBool
+ubidi_getMemory(BidiMemoryForAllocation *pMemory, int32_t *pSize, UBool mayAllocate, int32_t sizeNeeded);
+
+/* helper macros for each allocated array in UBiDi */
+#define getDirPropsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
+ (pBiDi)->mayAllocateText, (length))
+
+#define getLevelsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
+ (pBiDi)->mayAllocateText, (length))
+
+#define getRunsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
+ (pBiDi)->mayAllocateRuns, (length)*sizeof(Run))
+
+/* additional macros used by ubidi_open() - always allow allocation */
+#define getInitialDirPropsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
+ TRUE, (length))
+
+#define getInitialLevelsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
+ TRUE, (length))
+
+#define getInitialParasMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->parasMemory, &(pBiDi)->parasSize, \
+ TRUE, (length)*sizeof(Para))
+
+#define getInitialRunsMemory(pBiDi, length) \
+ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
+ TRUE, (length)*sizeof(Run))
+
+#endif
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidiln.c b/Build/source/libs/icu/icu-xetex/common/ubidiln.c
new file mode 100644
index 00000000000..8cb079c2c3c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidiln.c
@@ -0,0 +1,1346 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ubidiln.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 1999aug06
+* created by: Markus W. Scherer, updated by Matitiahu Allouche
+*/
+
+#include "cmemory.h"
+#include "unicode/utypes.h"
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "unicode/ubidi.h"
+#include "ubidiimp.h"
+#include "uassert.h"
+
+/*
+ * General remarks about the functions in this file:
+ *
+ * These functions deal with the aspects of potentially mixed-directional
+ * text in a single paragraph or in a line of a single paragraph
+ * which has already been processed according to
+ * the Unicode 3.0 BiDi algorithm as defined in
+ * http://www.unicode.org/unicode/reports/tr9/ , version 13,
+ * also described in The Unicode Standard, Version 4.0.1 .
+ *
+ * This means that there is a UBiDi object with a levels
+ * and a dirProps array.
+ * paraLevel and direction are also set.
+ * Only if the length of the text is zero, then levels==dirProps==NULL.
+ *
+ * The overall directionality of the paragraph
+ * or line is used to bypass the reordering steps if possible.
+ * Even purely RTL text does not need reordering there because
+ * the ubidi_getLogical/VisualIndex() functions can compute the
+ * index on the fly in such a case.
+ *
+ * The implementation of the access to same-level-runs and of the reordering
+ * do attempt to provide better performance and less memory usage compared to
+ * a direct implementation of especially rule (L2) with an array of
+ * one (32-bit) integer per text character.
+ *
+ * Here, the levels array is scanned as soon as necessary, and a vector of
+ * same-level-runs is created. Reordering then is done on this vector.
+ * For each run of text positions that were resolved to the same level,
+ * only 8 bytes are stored: the first text position of the run and the visual
+ * position behind the run after reordering.
+ * One sign bit is used to hold the directionality of the run.
+ * This is inefficient if there are many very short runs. If the average run
+ * length is <2, then this uses more memory.
+ *
+ * In a further attempt to save memory, the levels array is never changed
+ * after all the resolution rules (Xn, Wn, Nn, In).
+ * Many functions have to consider the field trailingWSStart:
+ * if it is less than length, then there is an implicit trailing run
+ * at the paraLevel,
+ * which is not reflected in the levels array.
+ * This allows a line UBiDi object to use the same levels array as
+ * its paragraph parent object.
+ *
+ * When a UBiDi object is created for a line of a paragraph, then the
+ * paragraph's levels and dirProps arrays are reused by way of setting
+ * a pointer into them, not by copying. This again saves memory and forbids to
+ * change the now shared levels for (L1).
+ */
+
+/* handle trailing WS (L1) -------------------------------------------------- */
+
+/*
+ * setTrailingWSStart() sets the start index for a trailing
+ * run of WS in the line. This is necessary because we do not modify
+ * the paragraph's levels array that we just point into.
+ * Using trailingWSStart is another form of performing (L1).
+ *
+ * To make subsequent operations easier, we also include the run
+ * before the WS if it is at the paraLevel - we merge the two here.
+ *
+ * This function is called only from ubidi_setLine(), so pBiDi->paraLevel is
+ * set correctly for the line even when contextual multiple paragraphs.
+ */
+static void
+setTrailingWSStart(UBiDi *pBiDi) {
+ /* pBiDi->direction!=UBIDI_MIXED */
+
+ const DirProp *dirProps=pBiDi->dirProps;
+ UBiDiLevel *levels=pBiDi->levels;
+ int32_t start=pBiDi->length;
+ UBiDiLevel paraLevel=pBiDi->paraLevel;
+
+ /* If the line is terminated by a block separator, all preceding WS etc...
+ are already set to paragraph level.
+ Setting trailingWSStart to pBidi->length will avoid changing the
+ level of B chars from 0 to paraLevel in ubidi_getLevels when
+ orderParagraphsLTR==TRUE.
+ */
+ if(NO_CONTEXT_RTL(dirProps[start-1])==B) {
+ pBiDi->trailingWSStart=start; /* currently == pBiDi->length */
+ return;
+ }
+ /* go backwards across all WS, BN, explicit codes */
+ while(start>0 && DIRPROP_FLAG_NC(dirProps[start-1])&MASK_WS) {
+ --start;
+ }
+
+ /* if the WS run can be merged with the previous run then do so here */
+ while(start>0 && levels[start-1]==paraLevel) {
+ --start;
+ }
+
+ pBiDi->trailingWSStart=start;
+}
+
+/* ubidi_setLine ------------------------------------------------------------ */
+
+U_CAPI void U_EXPORT2
+ubidi_setLine(const UBiDi *pParaBiDi,
+ int32_t start, int32_t limit,
+ UBiDi *pLineBiDi,
+ UErrorCode *pErrorCode) {
+ int32_t length;
+
+ /* check the argument values */
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ RETURN_VOID_IF_NOT_VALID_PARA(pParaBiDi, *pErrorCode);
+ RETURN_VOID_IF_BAD_RANGE(start, 0, limit, *pErrorCode);
+ RETURN_VOID_IF_BAD_RANGE(limit, 0, pParaBiDi->length+1, *pErrorCode);
+ if(pLineBiDi==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if(ubidi_getParagraph(pParaBiDi, start, NULL, NULL, NULL, pErrorCode) !=
+ ubidi_getParagraph(pParaBiDi, limit-1, NULL, NULL, NULL, pErrorCode)) {
+ /* the line crosses a paragraph boundary */
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ /* set the values in pLineBiDi from its pParaBiDi parent */
+ pLineBiDi->pParaBiDi=NULL; /* mark unfinished setLine */
+ pLineBiDi->text=pParaBiDi->text+start;
+ length=pLineBiDi->length=limit-start;
+ pLineBiDi->resultLength=pLineBiDi->originalLength=length;
+ pLineBiDi->paraLevel=GET_PARALEVEL(pParaBiDi, start);
+ pLineBiDi->paraCount=pParaBiDi->paraCount;
+ pLineBiDi->runs=NULL;
+ pLineBiDi->flags=0;
+ pLineBiDi->reorderingMode=pParaBiDi->reorderingMode;
+ pLineBiDi->reorderingOptions=pParaBiDi->reorderingOptions;
+ pLineBiDi->controlCount=0;
+ if(pParaBiDi->controlCount>0) {
+ int32_t j;
+ for(j=start; jtext[j])) {
+ pLineBiDi->controlCount++;
+ }
+ }
+ pLineBiDi->resultLength-=pLineBiDi->controlCount;
+ }
+
+ pLineBiDi->dirProps=pParaBiDi->dirProps+start;
+ pLineBiDi->levels=pParaBiDi->levels+start;
+ pLineBiDi->runCount=-1;
+
+ if(pParaBiDi->direction!=UBIDI_MIXED) {
+ /* the parent is already trivial */
+ pLineBiDi->direction=pParaBiDi->direction;
+
+ /*
+ * The parent's levels are all either
+ * implicitly or explicitly ==paraLevel;
+ * do the same here.
+ */
+ if(pParaBiDi->trailingWSStart<=start) {
+ pLineBiDi->trailingWSStart=0;
+ } else if(pParaBiDi->trailingWSStarttrailingWSStart=pParaBiDi->trailingWSStart-start;
+ } else {
+ pLineBiDi->trailingWSStart=length;
+ }
+ } else {
+ const UBiDiLevel *levels=pLineBiDi->levels;
+ int32_t i, trailingWSStart;
+ UBiDiLevel level;
+
+ setTrailingWSStart(pLineBiDi);
+ trailingWSStart=pLineBiDi->trailingWSStart;
+
+ /* recalculate pLineBiDi->direction */
+ if(trailingWSStart==0) {
+ /* all levels are at paraLevel */
+ pLineBiDi->direction=(UBiDiDirection)(pLineBiDi->paraLevel&1);
+ } else {
+ /* get the level of the first character */
+ level=(UBiDiLevel)(levels[0]&1);
+
+ /* if there is anything of a different level, then the line is mixed */
+ if(trailingWSStartparaLevel&1)!=level) {
+ /* the trailing WS is at paraLevel, which differs from levels[0] */
+ pLineBiDi->direction=UBIDI_MIXED;
+ } else {
+ /* see if levels[1..trailingWSStart-1] have the same direction as levels[0] and paraLevel */
+ i=1;
+ for(;;) {
+ if(i==trailingWSStart) {
+ /* the direction values match those in level */
+ pLineBiDi->direction=(UBiDiDirection)level;
+ break;
+ } else if((levels[i]&1)!=level) {
+ pLineBiDi->direction=UBIDI_MIXED;
+ break;
+ }
+ ++i;
+ }
+ }
+ }
+
+ switch(pLineBiDi->direction) {
+ case UBIDI_LTR:
+ /* make sure paraLevel is even */
+ pLineBiDi->paraLevel=(UBiDiLevel)((pLineBiDi->paraLevel+1)&~1);
+
+ /* all levels are implicitly at paraLevel (important for ubidi_getLevels()) */
+ pLineBiDi->trailingWSStart=0;
+ break;
+ case UBIDI_RTL:
+ /* make sure paraLevel is odd */
+ pLineBiDi->paraLevel|=1;
+
+ /* all levels are implicitly at paraLevel (important for ubidi_getLevels()) */
+ pLineBiDi->trailingWSStart=0;
+ break;
+ default:
+ break;
+ }
+ }
+ pLineBiDi->pParaBiDi=pParaBiDi; /* mark successful setLine */
+ return;
+}
+
+U_CAPI UBiDiLevel U_EXPORT2
+ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex) {
+ /* return paraLevel if in the trailing WS run, otherwise the real level */
+ if(!IS_VALID_PARA_OR_LINE(pBiDi) || charIndex<0 || pBiDi->length<=charIndex) {
+ return 0;
+ } else if(pBiDi->direction!=UBIDI_MIXED || charIndex>=pBiDi->trailingWSStart) {
+ return GET_PARALEVEL(pBiDi, charIndex);
+ } else {
+ return pBiDi->levels[charIndex];
+ }
+}
+
+U_CAPI const UBiDiLevel * U_EXPORT2
+ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
+ int32_t start, length;
+
+ RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrorCode, NULL);
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode, NULL);
+ if((length=pBiDi->length)<=0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ if((start=pBiDi->trailingWSStart)==length) {
+ /* the current levels array reflects the WS run */
+ return pBiDi->levels;
+ }
+
+ /*
+ * After the previous if(), we know that the levels array
+ * has an implicit trailing WS run and therefore does not fully
+ * reflect itself all the levels.
+ * This must be a UBiDi object for a line, and
+ * we need to create a new levels array.
+ */
+ if(getLevelsMemory(pBiDi, length)) {
+ UBiDiLevel *levels=pBiDi->levelsMemory;
+
+ if(start>0 && levels!=pBiDi->levels) {
+ uprv_memcpy(levels, pBiDi->levels, start);
+ }
+ /* pBiDi->paraLevel is ok even if contextual multiple paragraphs,
+ since pBidi is a line object */
+ uprv_memset(levels+start, pBiDi->paraLevel, length-start);
+
+ /* this new levels array is set for the line and reflects the WS run */
+ pBiDi->trailingWSStart=length;
+ return pBiDi->levels=levels;
+ } else {
+ /* out of memory */
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
+ int32_t *pLogicalLimit, UBiDiLevel *pLevel) {
+ UErrorCode errorCode;
+ int32_t runCount, visualStart, logicalLimit, logicalFirst, i;
+ Run iRun;
+
+ errorCode=U_ZERO_ERROR;
+ RETURN_VOID_IF_BAD_RANGE(logicalPosition, 0, pBiDi->length, errorCode);
+ /* ubidi_countRuns will check VALID_PARA_OR_LINE */
+ runCount=ubidi_countRuns((UBiDi *)pBiDi, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ return;
+ }
+ /* this is done based on runs rather than on levels since levels have
+ a special interpretation when UBIDI_REORDER_RUNS_ONLY
+ */
+ visualStart=logicalLimit=0;
+ iRun=pBiDi->runs[0];
+
+ for(i=0; iruns[i];
+ logicalFirst=GET_INDEX(iRun.logicalStart);
+ logicalLimit=logicalFirst+iRun.visualLimit-visualStart;
+ if((logicalPosition>=logicalFirst) &&
+ (logicalPositionreorderingMode==UBIDI_REORDER_RUNS_ONLY) {
+ *pLevel=(UBiDiLevel)GET_ODD_BIT(iRun.logicalStart);
+ }
+ else if(pBiDi->direction!=UBIDI_MIXED || logicalPosition>=pBiDi->trailingWSStart) {
+ *pLevel=GET_PARALEVEL(pBiDi, logicalPosition);
+ } else {
+ *pLevel=pBiDi->levels[logicalPosition];
+ }
+ }
+}
+
+/* runs API functions ------------------------------------------------------- */
+
+U_CAPI int32_t U_EXPORT2
+ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode) {
+ RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrorCode, -1);
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode, -1);
+ ubidi_getRuns(pBiDi, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return -1;
+ }
+ return pBiDi->runCount;
+}
+
+U_CAPI UBiDiDirection U_EXPORT2
+ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
+ int32_t *pLogicalStart, int32_t *pLength)
+{
+ int32_t start;
+ UErrorCode errorCode = U_ZERO_ERROR;
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, errorCode, UBIDI_LTR);
+ ubidi_getRuns(pBiDi, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ return UBIDI_LTR;
+ }
+ RETURN_IF_BAD_RANGE(runIndex, 0, pBiDi->runCount, errorCode, UBIDI_LTR);
+
+ start=pBiDi->runs[runIndex].logicalStart;
+ if(pLogicalStart!=NULL) {
+ *pLogicalStart=GET_INDEX(start);
+ }
+ if(pLength!=NULL) {
+ if(runIndex>0) {
+ *pLength=pBiDi->runs[runIndex].visualLimit-
+ pBiDi->runs[runIndex-1].visualLimit;
+ } else {
+ *pLength=pBiDi->runs[0].visualLimit;
+ }
+ }
+ return (UBiDiDirection)GET_ODD_BIT(start);
+}
+
+/* in trivial cases there is only one trivial run; called by ubidi_getRuns() */
+static void
+getSingleRun(UBiDi *pBiDi, UBiDiLevel level) {
+ /* simple, single-run case */
+ pBiDi->runs=pBiDi->simpleRuns;
+ pBiDi->runCount=1;
+
+ /* fill and reorder the single run */
+ pBiDi->runs[0].logicalStart=MAKE_INDEX_ODD_PAIR(0, level);
+ pBiDi->runs[0].visualLimit=pBiDi->length;
+ pBiDi->runs[0].insertRemove=0;
+}
+
+/* reorder the runs array (L2) ---------------------------------------------- */
+
+/*
+ * Reorder the same-level runs in the runs array.
+ * Here, runCount>1 and maxLevel>=minLevel>=paraLevel.
+ * All the visualStart fields=logical start before reordering.
+ * The "odd" bits are not set yet.
+ *
+ * Reordering with this data structure lends itself to some handy shortcuts:
+ *
+ * Since each run is moved but not modified, and since at the initial maxLevel
+ * each sequence of same-level runs consists of only one run each, we
+ * don't need to do anything there and can predecrement maxLevel.
+ * In many simple cases, the reordering is thus done entirely in the
+ * index mapping.
+ * Also, reordering occurs only down to the lowest odd level that occurs,
+ * which is minLevel|1. However, if the lowest level itself is odd, then
+ * in the last reordering the sequence of the runs at this level or higher
+ * will be all runs, and we don't need the elaborate loop to search for them.
+ * This is covered by ++minLevel instead of minLevel|=1 followed
+ * by an extra reorder-all after the reorder-some loop.
+ * About a trailing WS run:
+ * Such a run would need special treatment because its level is not
+ * reflected in levels[] if this is not a paragraph object.
+ * Instead, all characters from trailingWSStart on are implicitly at
+ * paraLevel.
+ * However, for all maxLevel>paraLevel, this run will never be reordered
+ * and does not need to be taken into account. maxLevel==paraLevel is only reordered
+ * if minLevel==paraLevel is odd, which is done in the extra segment.
+ * This means that for the main reordering loop we don't need to consider
+ * this run and can --runCount. If it is later part of the all-runs
+ * reordering, then runCount is adjusted accordingly.
+ */
+static void
+reorderLine(UBiDi *pBiDi, UBiDiLevel minLevel, UBiDiLevel maxLevel) {
+ Run *runs, tempRun;
+ UBiDiLevel *levels;
+ int32_t firstRun, endRun, limitRun, runCount;
+
+ /* nothing to do? */
+ if(maxLevel<=(minLevel|1)) {
+ return;
+ }
+
+ /*
+ * Reorder only down to the lowest odd level
+ * and reorder at an odd minLevel in a separate, simpler loop.
+ * See comments above for why minLevel is always incremented.
+ */
+ ++minLevel;
+
+ runs=pBiDi->runs;
+ levels=pBiDi->levels;
+ runCount=pBiDi->runCount;
+
+ /* do not include the WS run at paraLevel<=old minLevel except in the simple loop */
+ if(pBiDi->trailingWSStartlength) {
+ --runCount;
+ }
+
+ while(--maxLevel>=minLevel) {
+ firstRun=0;
+
+ /* loop for all sequences of runs */
+ for(;;) {
+ /* look for a sequence of runs that are all at >=maxLevel */
+ /* look for the first run of such a sequence */
+ while(firstRun=runCount) {
+ break; /* no more such runs */
+ }
+
+ /* look for the limit run of such a sequence (the run behind it) */
+ for(limitRun=firstRun; ++limitRun=maxLevel;) {}
+
+ /* Swap the entire sequence of runs from firstRun to limitRun-1. */
+ endRun=limitRun-1;
+ while(firstRuntrailingWSStart==pBiDi->length) {
+ --runCount;
+ }
+
+ /* Swap the entire sequence of all runs. (endRun==runCount) */
+ while(firstRunruns;
+ int32_t runCount=pBiDi->runCount, visualStart=0, i, length, logicalStart;
+
+ for(i=0; i=logicalStart) && (logicalIndex<(logicalStart+length))) {
+ return i;
+ }
+ visualStart+=length;
+ }
+ /* we should never get here */
+ U_ASSERT(FALSE);
+ *pErrorCode = U_INVALID_STATE_ERROR;
+ return 0;
+}
+
+/*
+ * Compute the runs array from the levels array.
+ * After ubidi_getRuns() returns TRUE, runCount is guaranteed to be >0
+ * and the runs are reordered.
+ * Odd-level runs have visualStart on their visual right edge and
+ * they progress visually to the left.
+ * If option UBIDI_OPTION_INSERT_MARKS is set, insertRemove will contain the
+ * sum of appropriate LRM/RLM_BEFORE/AFTER flags.
+ * If option UBIDI_OPTION_REMOVE_CONTROLS is set, insertRemove will contain the
+ * negative number of BiDi control characters within this run.
+ */
+U_CFUNC UBool
+ubidi_getRuns(UBiDi *pBiDi, UErrorCode *pErrorCode) {
+ /*
+ * This method returns immediately if the runs are already set. This
+ * includes the case of length==0 (handled in setPara)..
+ */
+ if (pBiDi->runCount>=0) {
+ return TRUE;
+ }
+
+ if(pBiDi->direction!=UBIDI_MIXED) {
+ /* simple, single-run case - this covers length==0 */
+ /* pBiDi->paraLevel is ok even for contextual multiple paragraphs */
+ getSingleRun(pBiDi, pBiDi->paraLevel);
+ } else /* UBIDI_MIXED, length>0 */ {
+ /* mixed directionality */
+ int32_t length=pBiDi->length, limit;
+ UBiDiLevel *levels=pBiDi->levels;
+ int32_t i, runCount;
+ UBiDiLevel level=UBIDI_DEFAULT_LTR; /* initialize with no valid level */
+ /*
+ * If there are WS characters at the end of the line
+ * and the run preceding them has a level different from
+ * paraLevel, then they will form their own run at paraLevel (L1).
+ * Count them separately.
+ * We need some special treatment for this in order to not
+ * modify the levels array which a line UBiDi object shares
+ * with its paragraph parent and its other line siblings.
+ * In other words, for the trailing WS, it may be
+ * levels[]!=paraLevel but we have to treat it like it were so.
+ */
+ limit=pBiDi->trailingWSStart;
+ /* count the runs, there is at least one non-WS run, and limit>0 */
+ runCount=0;
+ for(i=0; i1 || limit1 */
+ if(getRunsMemory(pBiDi, runCount)) {
+ runs=pBiDi->runsMemory;
+ } else {
+ return FALSE;
+ }
+
+ /* set the runs */
+ /* FOOD FOR THOUGHT: this could be optimized, e.g.:
+ * 464->444, 484->444, 575->555, 595->555
+ * However, that would take longer. Check also how it would
+ * interact with BiDi control removal and inserting Marks.
+ */
+ runIndex=0;
+
+ /* search for the run limits and initialize visualLimit values with the run lengths */
+ i=0;
+ do {
+ /* prepare this run */
+ start=i;
+ level=levels[i];
+ if(levelmaxLevel) {
+ maxLevel=level;
+ }
+
+ /* look for the run limit */
+ while(++iparaLevel is ok even
+ if contextual multiple paragraphs. */
+ if(pBiDi->paraLevelparaLevel;
+ }
+ }
+
+ /* set the object fields */
+ pBiDi->runs=runs;
+ pBiDi->runCount=runCount;
+
+ reorderLine(pBiDi, minLevel, maxLevel);
+
+ /* now add the direction flags and adjust the visualLimit's to be just that */
+ /* this loop will also handle the trailing WS run */
+ limit=0;
+ for(i=0; iparaLevel is ok even if
+ contextual multiple paragraphs. */
+ if(runIndexparaLevel & 1) != 0)? 0 : runIndex;
+
+ ADD_ODD_BIT_FROM_LEVEL(runs[trailingRun].logicalStart, pBiDi->paraLevel);
+ }
+ }
+ }
+
+ /* handle insert LRM/RLM BEFORE/AFTER run */
+ if(pBiDi->insertPoints.size>0) {
+ Point *point, *start=pBiDi->insertPoints.points,
+ *limit=start+pBiDi->insertPoints.size;
+ int32_t runIndex;
+ for(point=start; pointpos, pErrorCode);
+ pBiDi->runs[runIndex].insertRemove|=point->flag;
+ }
+ }
+
+ /* handle remove BiDi control characters */
+ if(pBiDi->controlCount>0) {
+ int32_t runIndex;
+ const UChar *start=pBiDi->text, *limit=start+pBiDi->length, *pu;
+ for(pu=start; puruns[runIndex].insertRemove--;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+static UBool
+prepareReorder(const UBiDiLevel *levels, int32_t length,
+ int32_t *indexMap,
+ UBiDiLevel *pMinLevel, UBiDiLevel *pMaxLevel) {
+ int32_t start;
+ UBiDiLevel level, minLevel, maxLevel;
+
+ if(levels==NULL || length<=0) {
+ return FALSE;
+ }
+
+ /* determine minLevel and maxLevel */
+ minLevel=UBIDI_MAX_EXPLICIT_LEVEL+1;
+ maxLevel=0;
+ for(start=length; start>0;) {
+ level=levels[--start];
+ if(level>UBIDI_MAX_EXPLICIT_LEVEL+1) {
+ return FALSE;
+ }
+ if(levelmaxLevel) {
+ maxLevel=level;
+ }
+ }
+ *pMinLevel=minLevel;
+ *pMaxLevel=maxLevel;
+
+ /* initialize the index map */
+ for(start=length; start>0;) {
+ --start;
+ indexMap[start]=start;
+ }
+
+ return TRUE;
+}
+
+/* reorder a line based on a levels array (L2) ------------------------------ */
+
+U_CAPI void U_EXPORT2
+ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap) {
+ int32_t start, limit, sumOfSosEos;
+ UBiDiLevel minLevel, maxLevel;
+
+ if(indexMap==NULL || !prepareReorder(levels, length, indexMap, &minLevel, &maxLevel)) {
+ return;
+ }
+
+ /* nothing to do? */
+ if(minLevel==maxLevel && (minLevel&1)==0) {
+ return;
+ }
+
+ /* reorder only down to the lowest odd level */
+ minLevel|=1;
+
+ /* loop maxLevel..minLevel */
+ do {
+ start=0;
+
+ /* loop for all sequences of levels to reorder at the current maxLevel */
+ for(;;) {
+ /* look for a sequence of levels that are all at >=maxLevel */
+ /* look for the first index of such a sequence */
+ while(start=length) {
+ break; /* no more such sequences */
+ }
+
+ /* look for the limit of such a sequence (the index behind it) */
+ for(limit=start; ++limit=maxLevel;) {}
+
+ /*
+ * sos=start of sequence, eos=end of sequence
+ *
+ * The closed (inclusive) interval from sos to eos includes all the logical
+ * and visual indexes within this sequence. They are logically and
+ * visually contiguous and in the same range.
+ *
+ * For each run, the new visual index=sos+eos-old visual index;
+ * we pre-add sos+eos into sumOfSosEos ->
+ * new visual index=sumOfSosEos-old visual index;
+ */
+ sumOfSosEos=start+limit-1;
+
+ /* reorder each index in the sequence */
+ do {
+ indexMap[start]=sumOfSosEos-indexMap[start];
+ } while(++start=minLevel);
+}
+
+U_CAPI void U_EXPORT2
+ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap) {
+ int32_t start, end, limit, temp;
+ UBiDiLevel minLevel, maxLevel;
+
+ if(indexMap==NULL || !prepareReorder(levels, length, indexMap, &minLevel, &maxLevel)) {
+ return;
+ }
+
+ /* nothing to do? */
+ if(minLevel==maxLevel && (minLevel&1)==0) {
+ return;
+ }
+
+ /* reorder only down to the lowest odd level */
+ minLevel|=1;
+
+ /* loop maxLevel..minLevel */
+ do {
+ start=0;
+
+ /* loop for all sequences of levels to reorder at the current maxLevel */
+ for(;;) {
+ /* look for a sequence of levels that are all at >=maxLevel */
+ /* look for the first index of such a sequence */
+ while(start=length) {
+ break; /* no more such runs */
+ }
+
+ /* look for the limit of such a sequence (the index behind it) */
+ for(limit=start; ++limit=maxLevel;) {}
+
+ /*
+ * Swap the entire interval of indexes from start to limit-1.
+ * We don't need to swap the levels for the purpose of this
+ * algorithm: the sequence of levels that we look at does not
+ * move anyway.
+ */
+ end=limit-1;
+ while(start=minLevel);
+}
+
+/* API functions for logical<->visual mapping ------------------------------- */
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode) {
+ int32_t visualIndex=UBIDI_MAP_NOWHERE;
+ RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrorCode, -1);
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode, -1);
+ RETURN_IF_BAD_RANGE(logicalIndex, 0, pBiDi->length, *pErrorCode, -1);
+
+ /* we can do the trivial cases without the runs array */
+ switch(pBiDi->direction) {
+ case UBIDI_LTR:
+ visualIndex=logicalIndex;
+ break;
+ case UBIDI_RTL:
+ visualIndex=pBiDi->length-logicalIndex-1;
+ break;
+ default:
+ if(!ubidi_getRuns(pBiDi, pErrorCode)) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ } else {
+ Run *runs=pBiDi->runs;
+ int32_t i, visualStart=0, offset, length;
+
+ /* linear search for the run, search on the visual runs */
+ for(i=0; irunCount; ++i) {
+ length=runs[i].visualLimit-visualStart;
+ offset=logicalIndex-GET_INDEX(runs[i].logicalStart);
+ if(offset>=0 && offset=pBiDi->runCount) {
+ return UBIDI_MAP_NOWHERE;
+ }
+ }
+ }
+
+ if(pBiDi->insertPoints.size>0) {
+ /* add the number of added marks until the calculated visual index */
+ Run *runs=pBiDi->runs;
+ int32_t i, length, insertRemove;
+ int32_t visualStart=0, markFound=0;
+ for(i=0; ; i++, visualStart+=length) {
+ length=runs[i].visualLimit-visualStart;
+ insertRemove=runs[i].insertRemove;
+ if(insertRemove & (LRM_BEFORE|RLM_BEFORE)) {
+ markFound++;
+ }
+ /* is it the run containing the visual index? */
+ if(visualIndexcontrolCount>0) {
+ /* subtract the number of controls until the calculated visual index */
+ Run *runs=pBiDi->runs;
+ int32_t i, j, start, limit, length, insertRemove;
+ int32_t visualStart=0, controlFound=0;
+ UChar uchar=pBiDi->text[logicalIndex];
+ /* is the logical index pointing to a control ? */
+ if(IS_BIDI_CONTROL_CHAR(uchar)) {
+ return UBIDI_MAP_NOWHERE;
+ }
+ /* loop on runs */
+ for(i=0; ; i++, visualStart+=length) {
+ length=runs[i].visualLimit-visualStart;
+ insertRemove=runs[i].insertRemove;
+ /* calculated visual index is beyond this run? */
+ if(visualIndex>=runs[i].visualLimit) {
+ controlFound-=insertRemove;
+ continue;
+ }
+ /* calculated visual index must be within current run */
+ if(insertRemove==0) {
+ return visualIndex-controlFound;
+ }
+ if(IS_EVEN_RUN(runs[i].logicalStart)) {
+ /* LTR: check from run start to logical index */
+ start=runs[i].logicalStart;
+ limit=logicalIndex;
+ } else {
+ /* RTL: check from logical index to run end */
+ start=logicalIndex+1;
+ limit=GET_INDEX(runs[i].logicalStart)+length;
+ }
+ for(j=start; jtext[j];
+ if(IS_BIDI_CONTROL_CHAR(uchar)) {
+ controlFound++;
+ }
+ }
+ return visualIndex-controlFound;
+ }
+ }
+
+ return visualIndex;
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode) {
+ Run *runs;
+ int32_t i, runCount, start;
+ RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrorCode, -1);
+ RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, *pErrorCode, -1);
+ RETURN_IF_BAD_RANGE(visualIndex, 0, pBiDi->resultLength, *pErrorCode, -1);
+ /* we can do the trivial cases without the runs array */
+ if(pBiDi->insertPoints.size==0 && pBiDi->controlCount==0) {
+ if(pBiDi->direction==UBIDI_LTR) {
+ return visualIndex;
+ }
+ else if(pBiDi->direction==UBIDI_RTL) {
+ return pBiDi->length-visualIndex-1;
+ }
+ }
+ if(!ubidi_getRuns(pBiDi, pErrorCode)) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ }
+
+ runs=pBiDi->runs;
+ runCount=pBiDi->runCount;
+ if(pBiDi->insertPoints.size>0) {
+ /* handle inserted LRM/RLM */
+ int32_t markFound=0, insertRemove;
+ int32_t visualStart=0, length;
+ runs=pBiDi->runs;
+ /* subtract number of marks until visual index */
+ for(i=0; ; i++, visualStart+=length) {
+ length=runs[i].visualLimit-visualStart;
+ insertRemove=runs[i].insertRemove;
+ if(insertRemove&(LRM_BEFORE|RLM_BEFORE)) {
+ if(visualIndex<=(visualStart+markFound)) {
+ return UBIDI_MAP_NOWHERE;
+ }
+ markFound++;
+ }
+ /* is adjusted visual index within this run? */
+ if(visualIndex<(runs[i].visualLimit+markFound)) {
+ visualIndex-=markFound;
+ break;
+ }
+ if(insertRemove&(LRM_AFTER|RLM_AFTER)) {
+ if(visualIndex==(visualStart+length+markFound)) {
+ return UBIDI_MAP_NOWHERE;
+ }
+ markFound++;
+ }
+ }
+ }
+ else if(pBiDi->controlCount>0) {
+ /* handle removed BiDi control characters */
+ int32_t controlFound=0, insertRemove, length;
+ int32_t logicalStart, logicalEnd, visualStart=0, j, k;
+ UChar uchar;
+ UBool evenRun;
+ /* add number of controls until visual index */
+ for(i=0; ; i++, visualStart+=length) {
+ length=runs[i].visualLimit-visualStart;
+ insertRemove=runs[i].insertRemove;
+ /* is adjusted visual index beyond current run? */
+ if(visualIndex>=(runs[i].visualLimit-controlFound+insertRemove)) {
+ controlFound-=insertRemove;
+ continue;
+ }
+ /* adjusted visual index is within current run */
+ if(insertRemove==0) {
+ visualIndex+=controlFound;
+ break;
+ }
+ /* count non-control chars until visualIndex */
+ logicalStart=runs[i].logicalStart;
+ evenRun=IS_EVEN_RUN(logicalStart);
+ REMOVE_ODD_BIT(logicalStart);
+ logicalEnd=logicalStart+length-1;
+ for(j=0; jtext[k];
+ if(IS_BIDI_CONTROL_CHAR(uchar)) {
+ controlFound++;
+ }
+ if((visualIndex+controlFound)==(visualStart+j)) {
+ break;
+ }
+ }
+ visualIndex+=controlFound;
+ break;
+ }
+ }
+ /* handle all cases */
+ if(runCount<=10) {
+ /* linear search for the run */
+ for(i=0; visualIndex>=runs[i].visualLimit; ++i) {}
+ } else {
+ /* binary search for the run */
+ int32_t begin=0, limit=runCount;
+
+ /* the middle if() is guaranteed to find the run, we don't need a loop limit */
+ for(;;) {
+ i=(begin+limit)/2;
+ if(visualIndex>=runs[i].visualLimit) {
+ begin=i+1;
+ } else if(i==0 || visualIndex>=runs[i-1].visualLimit) {
+ break;
+ } else {
+ limit=i;
+ }
+ }
+ }
+
+ start=runs[i].logicalStart;
+ if(IS_EVEN_RUN(start)) {
+ /* LTR */
+ /* the offset in runs[i] is visualIndex-runs[i-1].visualLimit */
+ if(i>0) {
+ visualIndex-=runs[i-1].visualLimit;
+ }
+ return start+visualIndex;
+ } else {
+ /* RTL */
+ return GET_INDEX(start)+runs[i].visualLimit-visualIndex-1;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode) {
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ /* ubidi_countRuns() checks for VALID_PARA_OR_LINE */
+ ubidi_countRuns(pBiDi, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ /* no op */
+ } else if(indexMap==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ /* fill a logical-to-visual index map using the runs[] */
+ int32_t visualStart, visualLimit, i, j, k;
+ int32_t logicalStart, logicalLimit;
+ Run *runs=pBiDi->runs;
+ if (pBiDi->length<=0) {
+ return;
+ }
+ if (pBiDi->length>pBiDi->resultLength) {
+ uprv_memset(indexMap, 0xFF, pBiDi->length*sizeof(int32_t));
+ }
+
+ visualStart=0;
+ for(j=0; jrunCount; ++j) {
+ logicalStart=GET_INDEX(runs[j].logicalStart);
+ visualLimit=runs[j].visualLimit;
+ if(IS_EVEN_RUN(runs[j].logicalStart)) {
+ do { /* LTR */
+ indexMap[logicalStart++]=visualStart++;
+ } while(visualStartinsertPoints.size>0) {
+ int32_t markFound=0, runCount=pBiDi->runCount;
+ int32_t length, insertRemove;
+ visualStart=0;
+ /* add number of marks found until each index */
+ for(i=0; i0) {
+ logicalStart=GET_INDEX(runs[i].logicalStart);
+ logicalLimit=logicalStart+length;
+ for(j=logicalStart; jcontrolCount>0) {
+ int32_t controlFound=0, runCount=pBiDi->runCount;
+ int32_t length, insertRemove;
+ UBool evenRun;
+ UChar uchar;
+ visualStart=0;
+ /* subtract number of controls found until each index */
+ for(i=0; itext[k];
+ if(IS_BIDI_CONTROL_CHAR(uchar)) {
+ controlFound++;
+ indexMap[k]=UBIDI_MAP_NOWHERE;
+ continue;
+ }
+ indexMap[k]-=controlFound;
+ }
+ }
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode) {
+ RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrorCode);
+ if(indexMap==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ /* ubidi_countRuns() checks for VALID_PARA_OR_LINE */
+ ubidi_countRuns(pBiDi, pErrorCode);
+ if(U_SUCCESS(*pErrorCode)) {
+ /* fill a visual-to-logical index map using the runs[] */
+ Run *runs=pBiDi->runs, *runsLimit=runs+pBiDi->runCount;
+ int32_t logicalStart, visualStart, visualLimit, *pi=indexMap;
+
+ if (pBiDi->resultLength<=0) {
+ return;
+ }
+ visualStart=0;
+ for(; runslogicalStart;
+ visualLimit=runs->visualLimit;
+ if(IS_EVEN_RUN(logicalStart)) {
+ do { /* LTR */
+ *pi++ = logicalStart++;
+ } while(++visualStartinsertPoints.size>0) {
+ int32_t markFound=0, runCount=pBiDi->runCount;
+ int32_t insertRemove, i, j, k;
+ runs=pBiDi->runs;
+ /* count all inserted marks */
+ for(i=0; iresultLength;
+ for(i=runCount-1; i>=0 && markFound>0; i--) {
+ insertRemove=runs[i].insertRemove;
+ if(insertRemove&(LRM_AFTER|RLM_AFTER)) {
+ indexMap[--k]= UBIDI_MAP_NOWHERE;
+ markFound--;
+ }
+ visualStart= i>0 ? runs[i-1].visualLimit : 0;
+ for(j=runs[i].visualLimit-1; j>=visualStart && markFound>0; j--) {
+ indexMap[--k]=indexMap[j];
+ }
+ if(insertRemove&(LRM_BEFORE|RLM_BEFORE)) {
+ indexMap[--k]= UBIDI_MAP_NOWHERE;
+ markFound--;
+ }
+ }
+ }
+ else if(pBiDi->controlCount>0) {
+ int32_t runCount=pBiDi->runCount, logicalEnd;
+ int32_t insertRemove, length, i, j, k, m;
+ UChar uchar;
+ UBool evenRun;
+ runs=pBiDi->runs;
+ visualStart=0;
+ /* move forward indexes by number of preceding controls */
+ k=0;
+ for(i=0; itext[m];
+ if(!IS_BIDI_CONTROL_CHAR(uchar)) {
+ indexMap[k++]=m;
+ }
+ }
+ }
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length) {
+ if(srcMap!=NULL && destMap!=NULL && length>0) {
+ const int32_t *pi;
+ int32_t destLength=-1, count=0;
+ /* find highest value and count positive indexes in srcMap */
+ pi=srcMap+length;
+ while(pi>srcMap) {
+ if(*--pi>destLength) {
+ destLength=*pi;
+ }
+ if(*pi>=0) {
+ count++;
+ }
+ }
+ destLength++; /* add 1 for origin 0 */
+ if(count0) {
+ if(*--pi>=0) {
+ destMap[*pi]=--length;
+ } else {
+ --length;
+ }
+ }
+ }
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/ubidiwrt.c b/Build/source/libs/icu/icu-xetex/common/ubidiwrt.c
new file mode 100644
index 00000000000..34b13711d2c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubidiwrt.c
@@ -0,0 +1,630 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2000-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ubidiwrt.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 1999aug06
+* created by: Markus W. Scherer, updated by Matitiahu Allouche
+*
+* This file contains implementations for BiDi functions that use
+* the core algorithm and core API to write reordered text.
+*/
+
+/* set import/export definitions */
+#ifndef U_COMMON_IMPLEMENTATION
+# define U_COMMON_IMPLEMENTATION
+#endif
+
+#include "unicode/utypes.h"
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "unicode/ubidi.h"
+#include "cmemory.h"
+#include "ustr_imp.h"
+#include "ubidiimp.h"
+
+/*
+ * The function implementations in this file are designed
+ * for UTF-16 and UTF-32, not for UTF-8.
+ *
+ * Assumptions that are not true for UTF-8:
+ * - Any code point always needs the same number of code units
+ * ("minimum-length-problem" of UTF-8)
+ * - The BiDi control characters need only one code unit each
+ *
+ * Further assumptions for all UTFs:
+ * - u_charMirror(c) needs the same number of code units as c
+ */
+#if UTF_SIZE==8
+# error reimplement ubidi_writeReordered() for UTF-8, see comment above
+#endif
+
+#define IS_COMBINING(type) ((1UL<<(type))&(1UL<0);
+ return srcLength;
+ }
+ case UBIDI_DO_MIRRORING: {
+ /* do mirroring */
+ int32_t i=0, j=0;
+ UChar32 c;
+
+ if(destSize0) {
+ c=*src++;
+ if(!IS_BIDI_CONTROL_CHAR(c)) {
+ --remaining;
+ }
+ }
+ return destSize-remaining;
+ }
+ *dest++=c;
+ }
+ } while(--srcLength>0);
+ return destSize-remaining;
+ }
+ default: {
+ /* remove BiDi control characters and do mirroring */
+ int32_t remaining=destSize;
+ int32_t i, j=0;
+ UChar32 c;
+ do {
+ i=0;
+ UTF_NEXT_CHAR(src, i, srcLength, c);
+ src+=i;
+ srcLength-=i;
+ if(!IS_BIDI_CONTROL_CHAR(c)) {
+ remaining-=i;
+ if(remaining<0) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+
+ /* preflight the length */
+ while(srcLength>0) {
+ c=*src++;
+ if(!IS_BIDI_CONTROL_CHAR(c)) {
+ --remaining;
+ }
+ --srcLength;
+ }
+ return destSize-remaining;
+ }
+ c=u_charMirror(c);
+ UTF_APPEND_CHAR_UNSAFE(dest, j, c);
+ }
+ } while(srcLength>0);
+ return j;
+ }
+ } /* end of switch */
+}
+
+static int32_t
+doWriteReverse(const UChar *src, int32_t srcLength,
+ UChar *dest, int32_t destSize,
+ uint16_t options,
+ UErrorCode *pErrorCode) {
+ /*
+ * RTL run -
+ *
+ * RTL runs need to be copied to the destination in reverse order
+ * of code points, not code units, to keep Unicode characters intact.
+ *
+ * The general strategy for this is to read the source text
+ * in backward order, collect all code units for a code point
+ * (and optionally following combining characters, see below),
+ * and copy all these code units in ascending order
+ * to the destination for this run.
+ *
+ * Several options request whether combining characters
+ * should be kept after their base characters,
+ * whether BiDi control characters should be removed, and
+ * whether characters should be replaced by their mirror-image
+ * equivalent Unicode characters.
+ */
+ int32_t i, j;
+ UChar32 c;
+
+ /* optimize for several combinations of options */
+ switch(options&(UBIDI_REMOVE_BIDI_CONTROLS|UBIDI_DO_MIRRORING|UBIDI_KEEP_BASE_COMBINING)) {
+ case 0:
+ /*
+ * With none of the "complicated" options set, the destination
+ * run will have the same length as the source run,
+ * and there is no mirroring and no keeping combining characters
+ * with their base characters.
+ */
+ if(destSize0);
+ break;
+ case UBIDI_KEEP_BASE_COMBINING:
+ /*
+ * Here, too, the destination
+ * run will have the same length as the source run,
+ * and there is no mirroring.
+ * We do need to keep combining characters with their base characters.
+ */
+ if(destSize0 && IS_COMBINING(u_charType(c)));
+
+ /* copy this "user character" */
+ j=srcLength;
+ do {
+ *dest++=src[j++];
+ } while(j0);
+ break;
+ default:
+ /*
+ * With several "complicated" options set, this is the most
+ * general and the slowest copying of an RTL run.
+ * We will do mirroring, remove BiDi controls, and
+ * keep combining characters with their base characters
+ * as requested.
+ */
+ if(!(options&UBIDI_REMOVE_BIDI_CONTROLS)) {
+ i=srcLength;
+ } else {
+ /* we need to find out the destination length of the run,
+ which will not include the BiDi control characters */
+ int32_t length=srcLength;
+ UChar ch;
+
+ i=0;
+ do {
+ ch=*src++;
+ if(!IS_BIDI_CONTROL_CHAR(ch)) {
+ ++i;
+ }
+ } while(--length>0);
+ src-=srcLength;
+ }
+
+ if(destSize0 && IS_COMBINING(u_charType(c))) {
+ UTF_PREV_CHAR(src, 0, srcLength, c);
+ }
+ }
+
+ if(options&UBIDI_REMOVE_BIDI_CONTROLS && IS_BIDI_CONTROL_CHAR(c)) {
+ /* do not copy this BiDi control character */
+ continue;
+ }
+
+ /* copy this "user character" */
+ j=srcLength;
+ if(options&UBIDI_DO_MIRRORING) {
+ /* mirror only the base character */
+ int32_t k=0;
+ c=u_charMirror(c);
+ UTF_APPEND_CHAR_UNSAFE(dest, k, c);
+ dest+=k;
+ j+=k;
+ }
+ while(j0);
+ break;
+ } /* end of switch */
+
+ return destSize;
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_writeReverse(const UChar *src, int32_t srcLength,
+ UChar *dest, int32_t destSize,
+ uint16_t options,
+ UErrorCode *pErrorCode) {
+ int32_t destLength;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* more error checking */
+ if( src==NULL || srcLength<-1 ||
+ destSize<0 || (destSize>0 && dest==NULL))
+ {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* do input and output overlap? */
+ if( dest!=NULL &&
+ ((src>=dest && src=src && dest0) {
+ destLength=doWriteReverse(src, srcLength, dest, destSize, options, pErrorCode);
+ } else {
+ /* nothing to do */
+ destLength=0;
+ }
+
+ return u_terminateUChars(dest, destSize, destLength, pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+ubidi_writeReordered(UBiDi *pBiDi,
+ UChar *dest, int32_t destSize,
+ uint16_t options,
+ UErrorCode *pErrorCode) {
+ const UChar *text;
+ UChar *saveDest;
+ int32_t length, destCapacity;
+ int32_t run, runCount, logicalStart, runLength;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* more error checking */
+ if( pBiDi==NULL ||
+ (text=pBiDi->text)==NULL || (length=pBiDi->length)<0 ||
+ destSize<0 || (destSize>0 && dest==NULL))
+ {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* do input and output overlap? */
+ if( dest!=NULL &&
+ ((text>=dest && text=text && destoriginalLength)))
+ {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ if(length==0) {
+ /* nothing to do */
+ return u_terminateUChars(dest, destSize, 0, pErrorCode);
+ }
+
+ runCount=ubidi_countRuns(pBiDi, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* destSize shrinks, later destination length=destCapacity-destSize */
+ saveDest=dest;
+ destCapacity=destSize;
+
+ /*
+ * Option "insert marks" implies UBIDI_INSERT_LRM_FOR_NUMERIC if the
+ * reordering mode (checked below) is appropriate.
+ */
+ if(pBiDi->reorderingOptions & UBIDI_OPTION_INSERT_MARKS) {
+ options|=UBIDI_INSERT_LRM_FOR_NUMERIC;
+ options&=~UBIDI_REMOVE_BIDI_CONTROLS;
+ }
+ /*
+ * Option "remove controls" implies UBIDI_REMOVE_BIDI_CONTROLS
+ * and cancels UBIDI_INSERT_LRM_FOR_NUMERIC.
+ */
+ if(pBiDi->reorderingOptions & UBIDI_OPTION_REMOVE_CONTROLS) {
+ options|=UBIDI_REMOVE_BIDI_CONTROLS;
+ options&=~UBIDI_INSERT_LRM_FOR_NUMERIC;
+ }
+ /*
+ * If we do not perform the "inverse BiDi" algorithm, then we
+ * don't need to insert any LRMs, and don't need to test for it.
+ */
+ if((pBiDi->reorderingMode != UBIDI_REORDER_INVERSE_NUMBERS_AS_L) &&
+ (pBiDi->reorderingMode != UBIDI_REORDER_INVERSE_LIKE_DIRECT) &&
+ (pBiDi->reorderingMode != UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL) &&
+ (pBiDi->reorderingMode != UBIDI_REORDER_RUNS_ONLY)) {
+ options&=~UBIDI_INSERT_LRM_FOR_NUMERIC;
+ }
+ /*
+ * Iterate through all visual runs and copy the run text segments to
+ * the destination, according to the options.
+ *
+ * The tests for where to insert LRMs ignore the fact that there may be
+ * BN codes or non-BMP code points at the beginning and end of a run;
+ * they may insert LRMs unnecessarily but the tests are faster this way
+ * (this would have to be improved for UTF-8).
+ *
+ * Note that the only errors that are set by doWriteXY() are buffer overflow
+ * errors. Ignore them until the end, and continue for preflighting.
+ */
+ if(!(options&UBIDI_OUTPUT_REVERSE)) {
+ /* forward output */
+ if(!(options&UBIDI_INSERT_LRM_FOR_NUMERIC)) {
+ /* do not insert BiDi controls */
+ for(run=0; rundirProps;
+ const UChar *src;
+ UChar uc;
+ UBiDiDirection dir;
+ int32_t markFlag;
+
+ for(run=0; runruns[run].insertRemove;
+ if(markFlag<0) { /* BiDi controls count */
+ markFlag=0;
+ }
+
+ if(UBIDI_LTR==dir) {
+ if((pBiDi->isInverse) &&
+ (/*run>0 &&*/ dirProps[logicalStart]!=L)) {
+ markFlag |= LRM_BEFORE;
+ }
+ if (markFlag & LRM_BEFORE) {
+ uc=LRM_CHAR;
+ }
+ else if (markFlag & RLM_BEFORE) {
+ uc=RLM_CHAR;
+ }
+ else uc=0;
+ if(uc) {
+ if(destSize>0) {
+ *dest++=uc;
+ }
+ --destSize;
+ }
+
+ runLength=doWriteForward(src, runLength,
+ dest, destSize,
+ (uint16_t)(options&~UBIDI_DO_MIRRORING), pErrorCode);
+ dest+=runLength;
+ destSize-=runLength;
+
+ if((pBiDi->isInverse) &&
+ (/*run0) {
+ *dest++=uc;
+ }
+ --destSize;
+ }
+ } else { /* RTL run */
+ if((pBiDi->isInverse) &&
+ (/*run>0 &&*/ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1])))) {
+ markFlag |= RLM_BEFORE;
+ }
+ if (markFlag & LRM_BEFORE) {
+ uc=LRM_CHAR;
+ }
+ else if (markFlag & RLM_BEFORE) {
+ uc=RLM_CHAR;
+ }
+ else uc=0;
+ if(uc) {
+ if(destSize>0) {
+ *dest++=uc;
+ }
+ --destSize;
+ }
+
+ runLength=doWriteReverse(src, runLength,
+ dest, destSize,
+ options, pErrorCode);
+ dest+=runLength;
+ destSize-=runLength;
+
+ if((pBiDi->isInverse) &&
+ (/*run0) {
+ *dest++=uc;
+ }
+ --destSize;
+ }
+ }
+ }
+ }
+ } else {
+ /* reverse output */
+ if(!(options&UBIDI_INSERT_LRM_FOR_NUMERIC)) {
+ /* do not insert BiDi controls */
+ for(run=runCount; --run>=0;) {
+ if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, run, &logicalStart, &runLength)) {
+ runLength=doWriteReverse(text+logicalStart, runLength,
+ dest, destSize,
+ (uint16_t)(options&~UBIDI_DO_MIRRORING), pErrorCode);
+ } else {
+ runLength=doWriteForward(text+logicalStart, runLength,
+ dest, destSize,
+ options, pErrorCode);
+ }
+ dest+=runLength;
+ destSize-=runLength;
+ }
+ } else {
+ /* insert BiDi controls for "inverse BiDi" */
+ const DirProp *dirProps=pBiDi->dirProps;
+ const UChar *src;
+ UBiDiDirection dir;
+
+ for(run=runCount; --run>=0;) {
+ /* reverse output */
+ dir=ubidi_getVisualRun(pBiDi, run, &logicalStart, &runLength);
+ src=text+logicalStart;
+
+ if(UBIDI_LTR==dir) {
+ if(/*run0) {
+ *dest++=LRM_CHAR;
+ }
+ --destSize;
+ }
+
+ runLength=doWriteReverse(src, runLength,
+ dest, destSize,
+ (uint16_t)(options&~UBIDI_DO_MIRRORING), pErrorCode);
+ dest+=runLength;
+ destSize-=runLength;
+
+ if(/*run>0 &&*/ dirProps[logicalStart]!=L) {
+ if(destSize>0) {
+ *dest++=LRM_CHAR;
+ }
+ --destSize;
+ }
+ } else {
+ if(/*run0) {
+ *dest++=RLM_CHAR;
+ }
+ --destSize;
+ }
+
+ runLength=doWriteForward(src, runLength,
+ dest, destSize,
+ options, pErrorCode);
+ dest+=runLength;
+ destSize-=runLength;
+
+ if(/*run>0 &&*/ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) {
+ if(destSize>0) {
+ *dest++=RLM_CHAR;
+ }
+ --destSize;
+ }
+ }
+ }
+ }
+ }
+
+ return u_terminateUChars(saveDest, destCapacity, destCapacity-destSize, pErrorCode);
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/ubrk.cpp b/Build/source/libs/icu/icu-xetex/common/ubrk.cpp
new file mode 100644
index 00000000000..89028100283
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubrk.cpp
@@ -0,0 +1,293 @@
+/*
+*****************************************************************************************
+* Copyright (C) 1996-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/ubrk.h"
+
+#include "unicode/brkiter.h"
+#include "unicode/uloc.h"
+#include "unicode/ustring.h"
+#include "unicode/uchriter.h"
+#include "unicode/rbbi.h"
+#include "rbbirb.h"
+#include "uassert.h"
+
+U_NAMESPACE_USE
+
+//----------------------------------------------------------------------------------------
+//
+// ubrk_open Create a canned type of break iterator based on type (word, line, etc.)
+// and locale.
+//
+//----------------------------------------------------------------------------------------
+U_CAPI UBreakIterator* U_EXPORT2
+ubrk_open(UBreakIteratorType type,
+ const char *locale,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status)
+{
+
+ if(U_FAILURE(*status)) return 0;
+
+ BreakIterator *result = 0;
+
+ switch(type) {
+
+ case UBRK_CHARACTER:
+ result = BreakIterator::createCharacterInstance(Locale(locale), *status);
+ break;
+
+ case UBRK_WORD:
+ result = BreakIterator::createWordInstance(Locale(locale), *status);
+ break;
+
+ case UBRK_LINE:
+ result = BreakIterator::createLineInstance(Locale(locale), *status);
+ break;
+
+ case UBRK_SENTENCE:
+ result = BreakIterator::createSentenceInstance(Locale(locale), *status);
+ break;
+
+ case UBRK_TITLE:
+ result = BreakIterator::createTitleInstance(Locale(locale), *status);
+ break;
+
+ default:
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+
+ // check for allocation error
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if(result == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+
+ UBreakIterator *uBI = (UBreakIterator *)result;
+ if (text != NULL) {
+ ubrk_setText(uBI, text, textLength, status);
+ }
+ return uBI;
+}
+
+
+
+//----------------------------------------------------------------------------------------
+//
+// ubrk_openRules open a break iterator from a set of break rules.
+// Invokes the rule builder.
+//
+//----------------------------------------------------------------------------------------
+U_CAPI UBreakIterator* U_EXPORT2
+ubrk_openRules( const UChar *rules,
+ int32_t rulesLength,
+ const UChar *text,
+ int32_t textLength,
+ UParseError *parseErr,
+ UErrorCode *status) {
+
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+
+ BreakIterator *result = 0;
+ UnicodeString ruleString(rules, rulesLength);
+ result = RBBIRuleBuilder::createRuleBasedBreakIterator(ruleString, *parseErr, *status);
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ UBreakIterator *uBI = (UBreakIterator *)result;
+ if (text != NULL) {
+ ubrk_setText(uBI, text, textLength, status);
+ }
+ return uBI;
+}
+
+
+
+
+
+U_CAPI UBreakIterator * U_EXPORT2
+ubrk_safeClone(
+ const UBreakIterator *bi,
+ void *stackBuffer,
+ int32_t *pBufferSize,
+ UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return 0;
+ }
+ if (!pBufferSize || !bi){
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ // Clear any incoming Safe Clone Allocated warning.
+ // Propagating this through to our return would really
+ // confuse our caller.
+ if (*status==U_SAFECLONE_ALLOCATED_WARNING) {
+ *status = U_ZERO_ERROR;
+ }
+ return (UBreakIterator *)(((BreakIterator*)bi)->
+ createBufferClone(stackBuffer, *pBufferSize, *status));
+}
+
+
+
+U_CAPI void U_EXPORT2
+ubrk_close(UBreakIterator *bi)
+{
+ BreakIterator *ubi = (BreakIterator*) bi;
+ if (ubi) {
+ if (ubi->isBufferClone()) {
+ ubi->~BreakIterator();
+ *(uint32_t *)ubi = 0xdeadbeef;
+ } else {
+ delete ubi;
+ }
+ }
+}
+
+U_CAPI void U_EXPORT2
+ubrk_setText(UBreakIterator* bi,
+ const UChar* text,
+ int32_t textLength,
+ UErrorCode* status)
+{
+ BreakIterator *brit = (BreakIterator *)bi;
+ UText ut = UTEXT_INITIALIZER;
+ utext_openUChars(&ut, text, textLength, status);
+ brit->setText(&ut, *status);
+ // A stack allocated UText wrapping a UCHar * string
+ // can be dumped without explicitly closing it.
+}
+
+
+
+U_CAPI void U_EXPORT2
+ubrk_setUText(UBreakIterator *bi,
+ UText *text,
+ UErrorCode *status)
+{
+ RuleBasedBreakIterator *brit = (RuleBasedBreakIterator *)bi;
+ brit->RuleBasedBreakIterator::setText(text, *status);
+}
+
+
+
+
+
+U_CAPI int32_t U_EXPORT2
+ubrk_current(const UBreakIterator *bi)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::current();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_next(UBreakIterator *bi)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::next();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_previous(UBreakIterator *bi)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::previous();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_first(UBreakIterator *bi)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::first();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_last(UBreakIterator *bi)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::last();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_preceding(UBreakIterator *bi,
+ int32_t offset)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::preceding(offset);
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_following(UBreakIterator *bi,
+ int32_t offset)
+{
+
+ return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::following(offset);
+}
+
+U_CAPI const char* U_EXPORT2
+ubrk_getAvailable(int32_t index)
+{
+
+ return uloc_getAvailable(index);
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_countAvailable()
+{
+
+ return uloc_countAvailable();
+}
+
+
+U_CAPI UBool U_EXPORT2
+ubrk_isBoundary(UBreakIterator *bi, int32_t offset)
+{
+ return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::isBoundary(offset);
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ubrk_getRuleStatus(UBreakIterator *bi)
+{
+ return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::getRuleStatus();
+}
+
+U_CAPI int32_t U_EXPORT2
+ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, UErrorCode *status)
+{
+ return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::getRuleStatusVec(fillInVec, capacity, *status);
+}
+
+
+U_CAPI const char* U_EXPORT2
+ubrk_getLocaleByType(const UBreakIterator *bi,
+ ULocDataLocaleType type,
+ UErrorCode* status)
+{
+ if (bi == NULL) {
+ if (U_SUCCESS(*status)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+ }
+ return ((BreakIterator*)bi)->getLocaleID(type, *status);
+}
+
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/Build/source/libs/icu/icu-xetex/common/ubrkimpl.h b/Build/source/libs/icu/icu-xetex/common/ubrkimpl.h
new file mode 100644
index 00000000000..e4909712566
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ubrkimpl.h
@@ -0,0 +1,13 @@
+/*
+**********************************************************************
+* Copyright (C) 2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#ifndef UBRKIMPL_H
+#define UBRKIMPL_H
+
+#define U_ICUDATA_BRKITR U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "brkitr"
+
+#endif /*UBRKIMPL_H*/
diff --git a/Build/source/libs/icu/icu-xetex/common/ucase.c b/Build/source/libs/icu/icu-xetex/common/ucase.c
new file mode 100644
index 00000000000..2352176be15
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucase.c
@@ -0,0 +1,1599 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2004-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: ucase.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004aug30
+* created by: Markus W. Scherer
+*
+* Low-level Unicode character/string case mapping code.
+* Much code moved here (and modified) from uchar.c.
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "unicode/udata.h" /* UDataInfo */
+#include "ucmndata.h" /* DataHeader */
+#include "udatamem.h"
+#include "umutex.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "utrie.h"
+#include "ucase.h"
+#include "ucln_cmn.h"
+
+struct UCaseProps {
+ UDataMemory *mem;
+ const int32_t *indexes;
+ const uint16_t *exceptions;
+ const UChar *unfold;
+
+ UTrie trie;
+ uint8_t formatVersion[4];
+};
+
+/* data loading etc. -------------------------------------------------------- */
+
+#define UCASE_HARDCODE_DATA 1
+
+#if UCASE_HARDCODE_DATA
+
+/* ucase_props_data.c is machine-generated by gencase --csource */
+#include "ucase_props_data.c"
+
+#else
+
+static UBool U_CALLCONV
+isAcceptable(void *context,
+ const char *type, const char *name,
+ const UDataInfo *pInfo) {
+ if(
+ pInfo->size>=20 &&
+ pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
+ pInfo->charsetFamily==U_CHARSET_FAMILY &&
+ pInfo->dataFormat[0]==UCASE_FMT_0 && /* dataFormat="cAsE" */
+ pInfo->dataFormat[1]==UCASE_FMT_1 &&
+ pInfo->dataFormat[2]==UCASE_FMT_2 &&
+ pInfo->dataFormat[3]==UCASE_FMT_3 &&
+ pInfo->formatVersion[0]==1 &&
+ pInfo->formatVersion[2]==UTRIE_SHIFT &&
+ pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
+ ) {
+ UCaseProps *csp=(UCaseProps *)context;
+ uprv_memcpy(csp->formatVersion, pInfo->formatVersion, 4);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static UCaseProps *
+ucase_openData(UCaseProps *cspProto,
+ const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
+ UCaseProps *csp;
+ int32_t size;
+
+ cspProto->indexes=(const int32_t *)bin;
+ if( (length>=0 && length<16*4) ||
+ cspProto->indexes[UCASE_IX_INDEX_TOP]<16
+ ) {
+ /* length or indexes[] too short for minimum indexes[] length of 16 */
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ size=cspProto->indexes[UCASE_IX_INDEX_TOP]*4;
+ if(length>=0) {
+ if(length>=size && length>=cspProto->indexes[UCASE_IX_LENGTH]) {
+ length-=size;
+ } else {
+ /* length too short for indexes[] or for the whole data length */
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ }
+ bin+=size;
+ /* from here on, assume that the sizes of the items fit into the total length */
+
+ /* unserialize the trie, after indexes[] */
+ size=cspProto->indexes[UCASE_IX_TRIE_SIZE];
+ utrie_unserialize(&cspProto->trie, bin, size, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ bin+=size;
+
+ /* get exceptions[] */
+ size=2*cspProto->indexes[UCASE_IX_EXC_LENGTH];
+ cspProto->exceptions=(const uint16_t *)bin;
+ bin+=size;
+
+ /* get unfold[] */
+ size=2*cspProto->indexes[UCASE_IX_UNFOLD_LENGTH];
+ if(size!=0) {
+ cspProto->unfold=(const UChar *)bin;
+ bin+=size;
+ } else {
+ cspProto->unfold=NULL;
+ }
+
+ /* allocate, copy, and return the new UCaseProps */
+ csp=(UCaseProps *)uprv_malloc(sizeof(UCaseProps));
+ if(csp==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ } else {
+ uprv_memcpy(csp, cspProto, sizeof(UCaseProps));
+ return csp;
+ }
+}
+
+U_CAPI UCaseProps * U_EXPORT2
+ucase_open(UErrorCode *pErrorCode) {
+ UCaseProps cspProto={ NULL }, *csp;
+
+ cspProto.mem=udata_openChoice(NULL, UCASE_DATA_TYPE, UCASE_DATA_NAME, isAcceptable, &cspProto, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ csp=ucase_openData(
+ &cspProto,
+ udata_getMemory(cspProto.mem),
+ udata_getLength(cspProto.mem),
+ pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ udata_close(cspProto.mem);
+ return NULL;
+ } else {
+ return csp;
+ }
+}
+
+U_CAPI UCaseProps * U_EXPORT2
+ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
+ UCaseProps cspProto={ NULL };
+ const DataHeader *hdr;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ if(bin==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ /* check the header */
+ if(length>=0 && length<20) {
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ hdr=(const DataHeader *)bin;
+ if(
+ !(hdr->dataHeader.magic1==0xda && hdr->dataHeader.magic2==0x27 &&
+ hdr->info.isBigEndian==U_IS_BIG_ENDIAN &&
+ isAcceptable(&cspProto, UCASE_DATA_TYPE, UCASE_DATA_NAME, &hdr->info))
+ ) {
+ *pErrorCode=U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+
+ bin+=hdr->dataHeader.headerSize;
+ if(length>=0) {
+ length-=hdr->dataHeader.headerSize;
+ }
+ return ucase_openData(&cspProto, bin, length, pErrorCode);
+}
+
+#endif
+
+U_CAPI void U_EXPORT2
+ucase_close(UCaseProps *csp) {
+ if(csp!=NULL) {
+#if !UCASE_HARDCODE_DATA
+ udata_close(csp->mem);
+#endif
+ uprv_free(csp);
+ }
+}
+
+/* UCaseProps singleton ----------------------------------------------------- */
+
+static UCaseProps *gCsp=NULL, *gCspDummy=NULL;
+#if !UCASE_HARDCODE_DATA
+static UErrorCode gErrorCode=U_ZERO_ERROR;
+static int8_t gHaveData=0;
+#endif
+
+static UBool U_CALLCONV ucase_cleanup(void) {
+ ucase_close(gCsp);
+ gCsp=NULL;
+ ucase_close(gCspDummy);
+ gCspDummy=NULL;
+#if !UCASE_HARDCODE_DATA
+ gErrorCode=U_ZERO_ERROR;
+ gHaveData=0;
+#endif
+ return TRUE;
+}
+
+U_CAPI const UCaseProps * U_EXPORT2
+ucase_getSingleton(UErrorCode *pErrorCode) {
+#if UCASE_HARDCODE_DATA
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ return &ucase_props_singleton;
+#else
+ int8_t haveData;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ UMTX_CHECK(NULL, gHaveData, haveData);
+
+ if(haveData>0) {
+ /* data was loaded */
+ return gCsp;
+ } else if(haveData<0) {
+ /* data loading failed */
+ *pErrorCode=gErrorCode;
+ return NULL;
+ } else /* haveData==0 */ {
+ /* load the data */
+ UCaseProps *csp=ucase_open(pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ gHaveData=-1;
+ gErrorCode=*pErrorCode;
+ return NULL;
+ }
+
+ /* set the static variables */
+ umtx_lock(NULL);
+ if(gCsp==NULL) {
+ gCsp=csp;
+ csp=NULL;
+ gHaveData=1;
+ ucln_common_registerCleanup(UCLN_COMMON_UCASE, ucase_cleanup);
+ }
+ umtx_unlock(NULL);
+
+ ucase_close(csp);
+ return gCsp;
+ }
+#endif
+}
+
+U_CAPI const UCaseProps * U_EXPORT2
+ucase_getDummy(UErrorCode *pErrorCode) {
+ UCaseProps *csp;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ UMTX_CHECK(NULL, gCspDummy, csp);
+
+ if(csp!=NULL) {
+ /* the dummy object was already created */
+ return csp;
+ } else /* csp==NULL */ {
+ /* create the dummy object */
+ int32_t *indexes;
+
+ csp=(UCaseProps *)uprv_malloc(sizeof(UCaseProps)+UCASE_IX_TOP*4+UTRIE_DUMMY_SIZE);
+ if(csp==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memset(csp, 0, sizeof(UCaseProps)+UCASE_IX_TOP*4);
+
+ csp->indexes=indexes=(int32_t *)(csp+1);
+ indexes[UCASE_IX_INDEX_TOP]=UCASE_IX_TOP;
+
+ indexes[UCASE_IX_TRIE_SIZE]=
+ utrie_unserializeDummy(&csp->trie, indexes+UCASE_IX_TOP, UTRIE_DUMMY_SIZE, 0, 0, TRUE, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ uprv_free(csp);
+ return NULL;
+ }
+
+ csp->formatVersion[0]=1;
+ csp->formatVersion[2]=UTRIE_SHIFT;
+ csp->formatVersion[3]=UTRIE_INDEX_SHIFT;
+
+ /* set the static variables */
+ umtx_lock(NULL);
+ if(gCspDummy==NULL) {
+ gCspDummy=csp;
+ csp=NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_UCASE, ucase_cleanup);
+ }
+ umtx_unlock(NULL);
+
+ uprv_free(csp);
+ return gCspDummy;
+ }
+}
+
+/* set of property starts for UnicodeSet ------------------------------------ */
+
+static UBool U_CALLCONV
+_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+ /* add the start code point to the USet */
+ const USetAdder *sa=(const USetAdder *)context;
+ sa->add(sa->set, start);
+ return TRUE;
+}
+
+U_CFUNC void U_EXPORT2
+ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ /* add the start code point of each same-value range of the trie */
+ utrie_enum(&csp->trie, NULL, _enumPropertyStartsRange, sa);
+
+ /* add code points with hardcoded properties, plus the ones following them */
+
+ /* (none right now, see comment below) */
+
+ /*
+ * Omit code points with hardcoded specialcasing properties
+ * because we do not build property UnicodeSets for them right now.
+ */
+}
+
+/* data access primitives --------------------------------------------------- */
+
+/* UTRIE_GET16() itself validates c */
+#define GET_PROPS(csp, c, result) \
+ UTRIE_GET16(&(csp)->trie, c, result);
+
+#define GET_EXCEPTIONS(csp, props) ((csp)->exceptions+((props)>>UCASE_EXC_SHIFT))
+
+#define PROPS_HAS_EXCEPTION(props) ((props)&UCASE_EXCEPTION)
+
+/* number of bits in an 8-bit integer value */
+static const uint8_t flagsOffset[256]={
+ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
+ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+ 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+ 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+ 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+ 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
+};
+
+#define HAS_SLOT(flags, index) ((flags)&(1<<(index)))
+#define SLOT_OFFSET(flags, index) flagsOffset[(flags)&((1<<(index))-1)]
+
+/*
+ * Get the value of an optional-value slot where HAS_SLOT(excWord, index).
+ *
+ * @param excWord (in) initial exceptions word
+ * @param index (in) desired slot index
+ * @param pExc16 (in/out) const uint16_t * after excWord=*pExc16++;
+ * moved to the last uint16_t of the value, use +1 for beginning of next slot
+ * @param value (out) int32_t or uint32_t output if hasSlot, otherwise not modified
+ */
+#define GET_SLOT_VALUE(excWord, index, pExc16, value) \
+ if(((excWord)&UCASE_EXC_DOUBLE_SLOTS)==0) { \
+ (pExc16)+=SLOT_OFFSET(excWord, index); \
+ (value)=*pExc16; \
+ } else { \
+ (pExc16)+=2*SLOT_OFFSET(excWord, index); \
+ (value)=*pExc16++; \
+ (value)=((value)<<16)|*pExc16; \
+ }
+
+/* simple case mappings ----------------------------------------------------- */
+
+U_CAPI UChar32 U_EXPORT2
+ucase_tolower(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
+ c+=UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+ uint16_t excWord=*pe++;
+ if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_LOWER, pe, c);
+ }
+ }
+ return c;
+}
+
+U_CAPI UChar32 U_EXPORT2
+ucase_toupper(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
+ c+=UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+ uint16_t excWord=*pe++;
+ if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_UPPER, pe, c);
+ }
+ }
+ return c;
+}
+
+U_CAPI UChar32 U_EXPORT2
+ucase_totitle(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
+ c+=UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+ uint16_t excWord=*pe++;
+ int32_t index;
+ if(HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
+ index=UCASE_EXC_TITLE;
+ } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
+ index=UCASE_EXC_UPPER;
+ } else {
+ return c;
+ }
+ GET_SLOT_VALUE(excWord, index, pe, c);
+ }
+ return c;
+}
+
+U_CFUNC void U_EXPORT2
+ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa) {
+ uint16_t props;
+
+ /*
+ * Hardcode the case closure of i and its relatives and ignore the
+ * data file data for these characters.
+ * The Turkic dotless i and dotted I with their case mapping conditions
+ * and case folding option make the related characters behave specially.
+ * This code matches their closure behavior to their case folding behavior.
+ */
+ static const UChar
+ iDot[2]= { 0x69, 0x307 };
+
+ switch(c) {
+ case 0x49:
+ /* regular i and I are in one equivalence class */
+ sa->add(sa->set, 0x69);
+ return;
+ case 0x69:
+ sa->add(sa->set, 0x49);
+ return;
+ case 0x130:
+ /* dotted I is in a class with <0069 0307> (for canonical equivalence with <0049 0307>) */
+ sa->addString(sa->set, iDot, 2);
+ return;
+ case 0x131:
+ /* dotless i is in a class by itself */
+ return;
+ default:
+ /* otherwise use the data file data */
+ break;
+ }
+
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
+ /* add the one simple case mapping, no matter what type it is */
+ int32_t delta=UCASE_GET_DELTA(props);
+ if(delta!=0) {
+ sa->add(sa->set, c+delta);
+ }
+ }
+ } else {
+ /*
+ * c has exceptions, so there may be multiple simple and/or
+ * full case mappings. Add them all.
+ */
+ const uint16_t *pe0, *pe=GET_EXCEPTIONS(csp, props);
+ const UChar *closure;
+ uint16_t excWord=*pe++;
+ int32_t index, closureLength, fullLength, length;
+
+ pe0=pe;
+
+ /* add all simple case mappings */
+ for(index=UCASE_EXC_LOWER; index<=UCASE_EXC_TITLE; ++index) {
+ if(HAS_SLOT(excWord, index)) {
+ pe=pe0;
+ GET_SLOT_VALUE(excWord, index, pe, c);
+ sa->add(sa->set, c);
+ }
+ }
+
+ /* get the closure string pointer & length */
+ if(HAS_SLOT(excWord, UCASE_EXC_CLOSURE)) {
+ pe=pe0;
+ GET_SLOT_VALUE(excWord, UCASE_EXC_CLOSURE, pe, closureLength);
+ closureLength&=UCASE_CLOSURE_MAX_LENGTH; /* higher bits are reserved */
+ closure=(const UChar *)pe+1; /* behind this slot, unless there are full case mappings */
+ } else {
+ closureLength=0;
+ closure=NULL;
+ }
+
+ /* add the full case folding */
+ if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
+ pe=pe0;
+ GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, fullLength);
+
+ /* start of full case mapping strings */
+ ++pe;
+
+ fullLength&=0xffff; /* bits 16 and higher are reserved */
+
+ /* skip the lowercase result string */
+ pe+=fullLength&UCASE_FULL_LOWER;
+ fullLength>>=4;
+
+ /* add the full case folding string */
+ length=fullLength&0xf;
+ if(length!=0) {
+ sa->addString(sa->set, (const UChar *)pe, length);
+ pe+=length;
+ }
+
+ /* skip the uppercase and titlecase strings */
+ fullLength>>=4;
+ pe+=fullLength&0xf;
+ fullLength>>=4;
+ pe+=fullLength;
+
+ closure=(const UChar *)pe; /* behind full case mappings */
+ }
+
+ /* add each code point in the closure string */
+ for(index=0; indexadd(sa->set, c);
+ }
+ }
+}
+
+/*
+ * compare s, which has a length, with t, which has a maximum length or is NUL-terminated
+ * must be length>0 and max>0 and length<=max
+ */
+static U_INLINE int32_t
+strcmpMax(const UChar *s, int32_t length, const UChar *t, int32_t max) {
+ int32_t c1, c2;
+
+ max-=length; /* we require length<=max, so no need to decrement max in the loop */
+ do {
+ c1=*s++;
+ c2=*t++;
+ if(c2==0) {
+ return 1; /* reached the end of t but not of s */
+ }
+ c1-=c2;
+ if(c1!=0) {
+ return c1; /* return difference result */
+ }
+ } while(--length>0);
+ /* ends with length==0 */
+
+ if(max==0 || *t==0) {
+ return 0; /* equal to length of both strings */
+ } else {
+ return -max; /* return lengh difference */
+ }
+}
+
+U_CFUNC UBool U_EXPORT2
+ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa) {
+ const UChar *unfold, *p;
+ int32_t i, start, limit, result, unfoldRows, unfoldRowWidth, unfoldStringWidth;
+
+ if(csp->unfold==NULL || s==NULL) {
+ return FALSE; /* no reverse case folding data, or no string */
+ }
+ if(length<=1) {
+ /* the string is too short to find any match */
+ /*
+ * more precise would be:
+ * if(!u_strHasMoreChar32Than(s, length, 1))
+ * but this does not make much practical difference because
+ * a single supplementary code point would just not be found
+ */
+ return FALSE;
+ }
+
+ unfold=csp->unfold;
+ unfoldRows=unfold[UCASE_UNFOLD_ROWS];
+ unfoldRowWidth=unfold[UCASE_UNFOLD_ROW_WIDTH];
+ unfoldStringWidth=unfold[UCASE_UNFOLD_STRING_WIDTH];
+ unfold+=unfoldRowWidth;
+
+ if(length>unfoldStringWidth) {
+ /* the string is too long to find any match */
+ return FALSE;
+ }
+
+ /* do a binary search for the string */
+ start=0;
+ limit=unfoldRows;
+ while(startadd(sa->set, c);
+ ucase_addCaseClosure(csp, c, sa);
+ }
+ return TRUE;
+ } else if(result<0) {
+ limit=i;
+ } else /* result>0 */ {
+ start=i+1;
+ }
+ }
+
+ return FALSE; /* string not found */
+}
+
+/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
+U_CAPI int32_t U_EXPORT2
+ucase_getType(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ return UCASE_GET_TYPE(props);
+}
+
+/** @return same as ucase_getType(), or <0 if c is case-ignorable */
+U_CAPI int32_t U_EXPORT2
+ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c) {
+ int32_t type;
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ type=UCASE_GET_TYPE(props);
+ if(type!=UCASE_NONE) {
+ return type;
+ } else if(
+ c==0x307 ||
+ (props&(UCASE_EXCEPTION|UCASE_CASE_IGNORABLE))==UCASE_CASE_IGNORABLE
+ ) {
+ return -1; /* case-ignorable */
+ } else {
+ return 0; /* c is neither cased nor case-ignorable */
+ }
+}
+
+/** @return UCASE_NO_DOT, UCASE_SOFT_DOTTED, UCASE_ABOVE, UCASE_OTHER_ACCENT */
+static U_INLINE int32_t
+getDotType(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ return props&UCASE_DOT_MASK;
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+ return (*pe>>UCASE_EXC_DOT_SHIFT)&UCASE_DOT_MASK;
+ }
+}
+
+U_CAPI UBool U_EXPORT2
+ucase_isSoftDotted(const UCaseProps *csp, UChar32 c) {
+ return (UBool)(getDotType(csp, c)==UCASE_SOFT_DOTTED);
+}
+
+U_CAPI UBool U_EXPORT2
+ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ return (UBool)((props&UCASE_SENSITIVE)!=0);
+}
+
+/* string casing ------------------------------------------------------------ */
+
+/*
+ * These internal functions form the core of string case mappings.
+ * They map single code points to result code points or strings and take
+ * all necessary conditions (context, locale ID, options) into account.
+ *
+ * They do not iterate over the source or write to the destination
+ * so that the same functions are useful for non-standard string storage,
+ * such as in a Replaceable (for Transliterator) or UTF-8/32 strings etc.
+ * For the same reason, the "surrounding text" context is passed in as a
+ * UCaseContextIterator which does not make any assumptions about
+ * the underlying storage.
+ *
+ * This section contains helper functions that check for conditions
+ * in the input text surrounding the current code point
+ * according to SpecialCasing.txt.
+ *
+ * Each helper function gets the index
+ * - after the current code point if it looks at following text
+ * - before the current code point if it looks at preceding text
+ *
+ * Unicode 3.2 UAX 21 "Case Mappings" defines the conditions as follows:
+ *
+ * Final_Sigma
+ * C is preceded by a sequence consisting of
+ * a cased letter and a case-ignorable sequence,
+ * and C is not followed by a sequence consisting of
+ * an ignorable sequence and then a cased letter.
+ *
+ * More_Above
+ * C is followed by one or more characters of combining class 230 (ABOVE)
+ * in the combining character sequence.
+ *
+ * After_Soft_Dotted
+ * The last preceding character with combining class of zero before C
+ * was Soft_Dotted,
+ * and there is no intervening combining character class 230 (ABOVE).
+ *
+ * Before_Dot
+ * C is followed by combining dot above (U+0307).
+ * Any sequence of characters with a combining class that is neither 0 nor 230
+ * may intervene between the current character and the combining dot above.
+ *
+ * The erratum from 2002-10-31 adds the condition
+ *
+ * After_I
+ * The last preceding base character was an uppercase I, and there is no
+ * intervening combining character class 230 (ABOVE).
+ *
+ * (See Jitterbug 2344 and the comments on After_I below.)
+ *
+ * Helper definitions in Unicode 3.2 UAX 21:
+ *
+ * D1. A character C is defined to be cased
+ * if it meets any of the following criteria:
+ *
+ * - The general category of C is Titlecase Letter (Lt)
+ * - In [CoreProps], C has one of the properties Uppercase, or Lowercase
+ * - Given D = NFD(C), then it is not the case that:
+ * D = UCD_lower(D) = UCD_upper(D) = UCD_title(D)
+ * (This third criterium does not add any characters to the list
+ * for Unicode 3.2. Ignored.)
+ *
+ * D2. A character C is defined to be case-ignorable
+ * if it meets either of the following criteria:
+ *
+ * - The general category of C is
+ * Nonspacing Mark (Mn), or Enclosing Mark (Me), or Format Control (Cf), or
+ * Letter Modifier (Lm), or Symbol Modifier (Sk)
+ * - C is one of the following characters
+ * U+0027 APOSTROPHE
+ * U+00AD SOFT HYPHEN (SHY)
+ * U+2019 RIGHT SINGLE QUOTATION MARK
+ * (the preferred character for apostrophe)
+ *
+ * D3. A case-ignorable sequence is a sequence of
+ * zero or more case-ignorable characters.
+ */
+
+enum {
+ LOC_UNKNOWN,
+ LOC_ROOT,
+ LOC_TURKISH,
+ LOC_LITHUANIAN
+};
+
+#define is_a(c) ((c)=='a' || (c)=='A')
+#define is_e(c) ((c)=='e' || (c)=='E')
+#define is_i(c) ((c)=='i' || (c)=='I')
+#define is_l(c) ((c)=='l' || (c)=='L')
+#define is_r(c) ((c)=='r' || (c)=='R')
+#define is_t(c) ((c)=='t' || (c)=='T')
+#define is_u(c) ((c)=='u' || (c)=='U')
+#define is_z(c) ((c)=='z' || (c)=='Z')
+
+/* separator? */
+#define is_sep(c) ((c)=='_' || (c)=='-' || (c)==0)
+
+/**
+ * Requires non-NULL locale ID but otherwise does the equivalent of
+ * checking for language codes as if uloc_getLanguage() were called:
+ * Accepts both 2- and 3-letter codes and accepts case variants.
+ */
+U_CFUNC int32_t
+ucase_getCaseLocale(const char *locale, int32_t *locCache) {
+ int32_t result;
+ char c;
+
+ if(locCache!=NULL && (result=*locCache)!=LOC_UNKNOWN) {
+ return result;
+ }
+
+ result=LOC_ROOT;
+
+ /*
+ * This function used to use uloc_getLanguage(), but the current code
+ * removes the dependency of this low-level code on uloc implementation code
+ * and is faster because not the whole locale ID has to be
+ * examined and copied/transformed.
+ *
+ * Because this code does not want to depend on uloc, the caller must
+ * pass in a non-NULL locale, i.e., may need to call uloc_getDefault().
+ */
+ c=*locale++;
+ if(is_t(c)) {
+ /* tr or tur? */
+ c=*locale++;
+ if(is_u(c)) {
+ c=*locale++;
+ }
+ if(is_r(c)) {
+ c=*locale;
+ if(is_sep(c)) {
+ result=LOC_TURKISH;
+ }
+ }
+ } else if(is_a(c)) {
+ /* az or aze? */
+ c=*locale++;
+ if(is_z(c)) {
+ c=*locale++;
+ if(is_e(c)) {
+ c=*locale;
+ }
+ if(is_sep(c)) {
+ result=LOC_TURKISH;
+ }
+ }
+ } else if(is_l(c)) {
+ /* lt or lit? */
+ c=*locale++;
+ if(is_i(c)) {
+ c=*locale++;
+ }
+ if(is_t(c)) {
+ c=*locale;
+ if(is_sep(c)) {
+ result=LOC_LITHUANIAN;
+ }
+ }
+ }
+
+ if(locCache!=NULL) {
+ *locCache=result;
+ }
+ return result;
+}
+
+/* Is followed by {case-ignorable}* cased ? (dir determines looking forward/backward) */
+static UBool
+isFollowedByCasedLetter(const UCaseProps *csp, UCaseContextIterator *iter, void *context, int8_t dir) {
+ UChar32 c;
+ uint16_t props;
+
+ if(iter==NULL) {
+ return FALSE;
+ }
+
+ for(/* dir!=0 sets direction */; (c=iter(context, dir))>=0; dir=0) {
+ GET_PROPS(csp, c, props);
+ if(UCASE_GET_TYPE(props)!=UCASE_NONE) {
+ return TRUE; /* followed by cased letter */
+ } else if(c==0x307 || (props&(UCASE_EXCEPTION|UCASE_CASE_IGNORABLE))==UCASE_CASE_IGNORABLE) {
+ /* case-ignorable, continue with the loop */
+ } else {
+ return FALSE; /* not ignorable */
+ }
+ }
+
+ return FALSE; /* not followed by cased letter */
+}
+
+/* Is preceded by Soft_Dotted character with no intervening cc=230 ? */
+static UBool
+isPrecededBySoftDotted(const UCaseProps *csp, UCaseContextIterator *iter, void *context) {
+ UChar32 c;
+ int32_t dotType;
+ int8_t dir;
+
+ if(iter==NULL) {
+ return FALSE;
+ }
+
+ for(dir=-1; (c=iter(context, dir))>=0; dir=0) {
+ dotType=getDotType(csp, c);
+ if(dotType==UCASE_SOFT_DOTTED) {
+ return TRUE; /* preceded by TYPE_i */
+ } else if(dotType!=UCASE_OTHER_ACCENT) {
+ return FALSE; /* preceded by different base character (not TYPE_i), or intervening cc==230 */
+ }
+ }
+
+ return FALSE; /* not preceded by TYPE_i */
+}
+
+/*
+ * See Jitterbug 2344:
+ * The condition After_I for Turkic-lowercasing of U+0307 combining dot above
+ * is checked in ICU 2.0, 2.1, 2.6 but was not in 2.2 & 2.4 because
+ * we made those releases compatible with Unicode 3.2 which had not fixed
+ * a related bug in SpecialCasing.txt.
+ *
+ * From the Jitterbug 2344 text:
+ * ... this bug is listed as a Unicode erratum
+ * from 2002-10-31 at http://www.unicode.org/uni2errata/UnicodeErrata.html
+ *
+ * There are two errors in SpecialCasing.txt.
+ * 1. Missing semicolons on two lines. ... [irrelevant for ICU]
+ * 2. An incorrect context definition. Correct as follows:
+ * < 0307; ; 0307; 0307; tr After_Soft_Dotted; # COMBINING DOT ABOVE
+ * < 0307; ; 0307; 0307; az After_Soft_Dotted; # COMBINING DOT ABOVE
+ * ---
+ * > 0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
+ * > 0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
+ * where the context After_I is defined as:
+ * The last preceding base character was an uppercase I, and there is no
+ * intervening combining character class 230 (ABOVE).
+ *
+ *
+ * Note that SpecialCasing.txt even in Unicode 3.2 described the condition as:
+ *
+ * # When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
+ * # This matches the behavior of the canonically equivalent I-dot_above
+ *
+ * See also the description in this place in older versions of uchar.c (revision 1.100).
+ *
+ * Markus W. Scherer 2003-feb-15
+ */
+
+/* Is preceded by base character 'I' with no intervening cc=230 ? */
+static UBool
+isPrecededBy_I(const UCaseProps *csp, UCaseContextIterator *iter, void *context) {
+ UChar32 c;
+ int32_t dotType;
+ int8_t dir;
+
+ if(iter==NULL) {
+ return FALSE;
+ }
+
+ for(dir=-1; (c=iter(context, dir))>=0; dir=0) {
+ if(c==0x49) {
+ return TRUE; /* preceded by I */
+ }
+ dotType=getDotType(csp, c);
+ if(dotType!=UCASE_OTHER_ACCENT) {
+ return FALSE; /* preceded by different base character (not I), or intervening cc==230 */
+ }
+ }
+
+ return FALSE; /* not preceded by I */
+}
+
+/* Is followed by one or more cc==230 ? */
+static UBool
+isFollowedByMoreAbove(const UCaseProps *csp, UCaseContextIterator *iter, void *context) {
+ UChar32 c;
+ int32_t dotType;
+ int8_t dir;
+
+ if(iter==NULL) {
+ return FALSE;
+ }
+
+ for(dir=1; (c=iter(context, dir))>=0; dir=0) {
+ dotType=getDotType(csp, c);
+ if(dotType==UCASE_ABOVE) {
+ return TRUE; /* at least one cc==230 following */
+ } else if(dotType!=UCASE_OTHER_ACCENT) {
+ return FALSE; /* next base character, no more cc==230 following */
+ }
+ }
+
+ return FALSE; /* no more cc==230 following */
+}
+
+/* Is followed by a dot above (without cc==230 in between) ? */
+static UBool
+isFollowedByDotAbove(const UCaseProps *csp, UCaseContextIterator *iter, void *context) {
+ UChar32 c;
+ int32_t dotType;
+ int8_t dir;
+
+ if(iter==NULL) {
+ return FALSE;
+ }
+
+ for(dir=1; (c=iter(context, dir))>=0; dir=0) {
+ if(c==0x307) {
+ return TRUE;
+ }
+ dotType=getDotType(csp, c);
+ if(dotType!=UCASE_OTHER_ACCENT) {
+ return FALSE; /* next base character or cc==230 in between */
+ }
+ }
+
+ return FALSE; /* no dot above following */
+}
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullLower(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache) {
+ static const UChar
+ iDot[2]= { 0x69, 0x307 },
+ jDot[2]= { 0x6a, 0x307 },
+ iOgonekDot[3]= { 0x12f, 0x307 },
+ iDotGrave[3]= { 0x69, 0x307, 0x300 },
+ iDotAcute[3]= { 0x69, 0x307, 0x301 },
+ iDotTilde[3]= { 0x69, 0x307, 0x303 };
+
+ UChar32 result;
+ uint16_t props;
+
+ result=c;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
+ result=c+UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props), *pe2;
+ uint16_t excWord=*pe++;
+ int32_t full;
+
+ pe2=pe;
+
+ if(excWord&UCASE_EXC_CONDITIONAL_SPECIAL) {
+ /* use hardcoded conditions and mappings */
+ int32_t loc=ucase_getCaseLocale(locale, locCache);
+
+ /*
+ * Test for conditional mappings first
+ * (otherwise the unconditional default mappings are always taken),
+ * then test for characters that have unconditional mappings in SpecialCasing.txt,
+ * then get the UnicodeData.txt mappings.
+ */
+ if( loc==LOC_LITHUANIAN &&
+ /* base characters, find accents above */
+ (((c==0x49 || c==0x4a || c==0x12e) &&
+ isFollowedByMoreAbove(csp, iter, context)) ||
+ /* precomposed with accent above, no need to find one */
+ (c==0xcc || c==0xcd || c==0x128))
+ ) {
+ /*
+ # Lithuanian
+
+ # Lithuanian retains the dot in a lowercase i when followed by accents.
+
+ # Introduce an explicit dot above when lowercasing capital I's and J's
+ # whenever there are more accents above.
+ # (of the accents used in Lithuanian: grave, acute, tilde above, and ogonek)
+
+ 0049; 0069 0307; 0049; 0049; lt More_Above; # LATIN CAPITAL LETTER I
+ 004A; 006A 0307; 004A; 004A; lt More_Above; # LATIN CAPITAL LETTER J
+ 012E; 012F 0307; 012E; 012E; lt More_Above; # LATIN CAPITAL LETTER I WITH OGONEK
+ 00CC; 0069 0307 0300; 00CC; 00CC; lt; # LATIN CAPITAL LETTER I WITH GRAVE
+ 00CD; 0069 0307 0301; 00CD; 00CD; lt; # LATIN CAPITAL LETTER I WITH ACUTE
+ 0128; 0069 0307 0303; 0128; 0128; lt; # LATIN CAPITAL LETTER I WITH TILDE
+ */
+ switch(c) {
+ case 0x49: /* LATIN CAPITAL LETTER I */
+ *pString=iDot;
+ return 2;
+ case 0x4a: /* LATIN CAPITAL LETTER J */
+ *pString=jDot;
+ return 2;
+ case 0x12e: /* LATIN CAPITAL LETTER I WITH OGONEK */
+ *pString=iOgonekDot;
+ return 2;
+ case 0xcc: /* LATIN CAPITAL LETTER I WITH GRAVE */
+ *pString=iDotGrave;
+ return 3;
+ case 0xcd: /* LATIN CAPITAL LETTER I WITH ACUTE */
+ *pString=iDotAcute;
+ return 3;
+ case 0x128: /* LATIN CAPITAL LETTER I WITH TILDE */
+ *pString=iDotTilde;
+ return 3;
+ default:
+ return 0; /* will not occur */
+ }
+ /* # Turkish and Azeri */
+ } else if(loc==LOC_TURKISH && c==0x130) {
+ /*
+ # I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
+ # The following rules handle those cases.
+
+ 0130; 0069; 0130; 0130; tr # LATIN CAPITAL LETTER I WITH DOT ABOVE
+ 0130; 0069; 0130; 0130; az # LATIN CAPITAL LETTER I WITH DOT ABOVE
+ */
+ return 0x69;
+ } else if(loc==LOC_TURKISH && c==0x307 && isPrecededBy_I(csp, iter, context)) {
+ /*
+ # When lowercasing, remove dot_above in the sequence I + dot_above, which will turn into i.
+ # This matches the behavior of the canonically equivalent I-dot_above
+
+ 0307; ; 0307; 0307; tr After_I; # COMBINING DOT ABOVE
+ 0307; ; 0307; 0307; az After_I; # COMBINING DOT ABOVE
+ */
+ return 0; /* remove the dot (continue without output) */
+ } else if(loc==LOC_TURKISH && c==0x49 && !isFollowedByDotAbove(csp, iter, context)) {
+ /*
+ # When lowercasing, unless an I is before a dot_above, it turns into a dotless i.
+
+ 0049; 0131; 0049; 0049; tr Not_Before_Dot; # LATIN CAPITAL LETTER I
+ 0049; 0131; 0049; 0049; az Not_Before_Dot; # LATIN CAPITAL LETTER I
+ */
+ return 0x131;
+ } else if(c==0x130) {
+ /*
+ # Preserve canonical equivalence for I with dot. Turkic is handled below.
+
+ 0130; 0069 0307; 0130; 0130; # LATIN CAPITAL LETTER I WITH DOT ABOVE
+ */
+ *pString=iDot;
+ return 2;
+ } else if( c==0x3a3 &&
+ !isFollowedByCasedLetter(csp, iter, context, 1) &&
+ isFollowedByCasedLetter(csp, iter, context, -1) /* -1=preceded */
+ ) {
+ /* greek capital sigma maps depending on surrounding cased letters (see SpecialCasing.txt) */
+ /*
+ # Special case for final form of sigma
+
+ 03A3; 03C2; 03A3; 03A3; Final_Sigma; # GREEK CAPITAL LETTER SIGMA
+ */
+ return 0x3c2; /* greek small final sigma */
+ } else {
+ /* no known conditional special case mapping, use a normal mapping */
+ }
+ } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
+ full&=UCASE_FULL_LOWER;
+ if(full!=0) {
+ /* set the output pointer to the lowercase mapping */
+ *pString=pe+1;
+
+ /* return the string length */
+ return full;
+ }
+ }
+
+ if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_LOWER, pe2, result);
+ }
+ }
+
+ return (result==c) ? ~result : result;
+}
+
+/* internal */
+static int32_t
+toUpperOrTitle(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache,
+ UBool upperNotTitle) {
+ UChar32 result;
+ uint16_t props;
+
+ result=c;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)==UCASE_LOWER) {
+ result=c+UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props), *pe2;
+ uint16_t excWord=*pe++;
+ int32_t full, index;
+
+ pe2=pe;
+
+ if(excWord&UCASE_EXC_CONDITIONAL_SPECIAL) {
+ /* use hardcoded conditions and mappings */
+ int32_t loc=ucase_getCaseLocale(locale, locCache);
+
+ if(loc==LOC_TURKISH && c==0x69) {
+ /*
+ # Turkish and Azeri
+
+ # I and i-dotless; I-dot and i are case pairs in Turkish and Azeri
+ # The following rules handle those cases.
+
+ # When uppercasing, i turns into a dotted capital I
+
+ 0069; 0069; 0130; 0130; tr; # LATIN SMALL LETTER I
+ 0069; 0069; 0130; 0130; az; # LATIN SMALL LETTER I
+ */
+ return 0x130;
+ } else if(loc==LOC_LITHUANIAN && c==0x307 && isPrecededBySoftDotted(csp, iter, context)) {
+ /*
+ # Lithuanian
+
+ # Lithuanian retains the dot in a lowercase i when followed by accents.
+
+ # Remove DOT ABOVE after "i" with upper or titlecase
+
+ 0307; 0307; ; ; lt After_Soft_Dotted; # COMBINING DOT ABOVE
+ */
+ return 0; /* remove the dot (continue without output) */
+ } else {
+ /* no known conditional special case mapping, use a normal mapping */
+ }
+ } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
+
+ /* start of full case mapping strings */
+ ++pe;
+
+ /* skip the lowercase and case-folding result strings */
+ pe+=full&UCASE_FULL_LOWER;
+ full>>=4;
+ pe+=full&0xf;
+ full>>=4;
+
+ if(upperNotTitle) {
+ full&=0xf;
+ } else {
+ /* skip the uppercase result string */
+ pe+=full&0xf;
+ full=(full>>4)&0xf;
+ }
+
+ if(full!=0) {
+ /* set the output pointer to the result string */
+ *pString=pe;
+
+ /* return the string length */
+ return full;
+ }
+ }
+
+ if(!upperNotTitle && HAS_SLOT(excWord, UCASE_EXC_TITLE)) {
+ index=UCASE_EXC_TITLE;
+ } else if(HAS_SLOT(excWord, UCASE_EXC_UPPER)) {
+ /* here, titlecase is same as uppercase */
+ index=UCASE_EXC_UPPER;
+ } else {
+ return ~c;
+ }
+ GET_SLOT_VALUE(excWord, index, pe2, result);
+ }
+
+ return (result==c) ? ~result : result;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullUpper(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache) {
+ return toUpperOrTitle(csp, c, iter, context, pString, locale, locCache, TRUE);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache) {
+ return toUpperOrTitle(csp, c, iter, context, pString, locale, locCache, FALSE);
+}
+
+/* case folding ------------------------------------------------------------- */
+
+/*
+ * Case folding is similar to lowercasing.
+ * The result may be a simple mapping, i.e., a single code point, or
+ * a full mapping, i.e., a string.
+ * If the case folding for a code point is the same as its simple (1:1) lowercase mapping,
+ * then only the lowercase mapping is stored.
+ *
+ * Some special cases are hardcoded because their conditions cannot be
+ * parsed and processed from CaseFolding.txt.
+ *
+ * Unicode 3.2 CaseFolding.txt specifies for its status field:
+
+# C: common case folding, common mappings shared by both simple and full mappings.
+# F: full case folding, mappings that cause strings to grow in length. Multiple characters are separated by spaces.
+# S: simple case folding, mappings to single characters where different from F.
+# T: special case for uppercase I and dotted uppercase I
+# - For non-Turkic languages, this mapping is normally not used.
+# - For Turkic languages (tr, az), this mapping can be used instead of the normal mapping for these characters.
+#
+# Usage:
+# A. To do a simple case folding, use the mappings with status C + S.
+# B. To do a full case folding, use the mappings with status C + F.
+#
+# The mappings with status T can be used or omitted depending on the desired case-folding
+# behavior. (The default option is to exclude them.)
+
+ * Unicode 3.2 has 'T' mappings as follows:
+
+0049; T; 0131; # LATIN CAPITAL LETTER I
+0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE
+
+ * while the default mappings for these code points are:
+
+0049; C; 0069; # LATIN CAPITAL LETTER I
+0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE
+
+ * U+0130 has no simple case folding (simple-case-folds to itself).
+ */
+
+/* return the simple case folding mapping for c */
+U_CAPI UChar32 U_EXPORT2
+ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options) {
+ uint16_t props;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
+ c+=UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props);
+ uint16_t excWord=*pe++;
+ int32_t index;
+ if(excWord&UCASE_EXC_CONDITIONAL_FOLD) {
+ /* special case folding mappings, hardcoded */
+ if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
+ /* default mappings */
+ if(c==0x49) {
+ /* 0049; C; 0069; # LATIN CAPITAL LETTER I */
+ return 0x69;
+ } else if(c==0x130) {
+ /* no simple case folding for U+0130 */
+ return c;
+ }
+ } else {
+ /* Turkic mappings */
+ if(c==0x49) {
+ /* 0049; T; 0131; # LATIN CAPITAL LETTER I */
+ return 0x131;
+ } else if(c==0x130) {
+ /* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
+ return 0x69;
+ }
+ }
+ }
+ if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
+ index=UCASE_EXC_FOLD;
+ } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
+ index=UCASE_EXC_LOWER;
+ } else {
+ return c;
+ }
+ GET_SLOT_VALUE(excWord, index, pe, c);
+ }
+ return c;
+}
+
+/*
+ * Issue for canonical caseless match (UAX #21):
+ * Turkic casefolding (using "T" mappings in CaseFolding.txt) does not preserve
+ * canonical equivalence, unlike default-option casefolding.
+ * For example, I-grave and I + grave fold to strings that are not canonically
+ * equivalent.
+ * For more details, see the comment in unorm_compare() in unorm.cpp
+ * and the intermediate prototype changes for Jitterbug 2021.
+ * (For example, revision 1.104 of uchar.c and 1.4 of CaseFolding.txt.)
+ *
+ * This did not get fixed because it appears that it is not possible to fix
+ * it for uppercase and lowercase characters (I-grave vs. i-grave)
+ * together in a way that they still fold to common result strings.
+ */
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
+ const UChar **pString,
+ uint32_t options) {
+ static const UChar
+ iDot[2]= { 0x69, 0x307 };
+
+ UChar32 result;
+ uint16_t props;
+
+ result=c;
+ GET_PROPS(csp, c, props);
+ if(!PROPS_HAS_EXCEPTION(props)) {
+ if(UCASE_GET_TYPE(props)>=UCASE_UPPER) {
+ result=c+UCASE_GET_DELTA(props);
+ }
+ } else {
+ const uint16_t *pe=GET_EXCEPTIONS(csp, props), *pe2;
+ uint16_t excWord=*pe++;
+ int32_t full, index;
+
+ pe2=pe;
+
+ if(excWord&UCASE_EXC_CONDITIONAL_FOLD) {
+ /* use hardcoded conditions and mappings */
+ if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) {
+ /* default mappings */
+ if(c==0x49) {
+ /* 0049; C; 0069; # LATIN CAPITAL LETTER I */
+ return 0x69;
+ } else if(c==0x130) {
+ /* 0130; F; 0069 0307; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
+ *pString=iDot;
+ return 2;
+ }
+ } else {
+ /* Turkic mappings */
+ if(c==0x49) {
+ /* 0049; T; 0131; # LATIN CAPITAL LETTER I */
+ return 0x131;
+ } else if(c==0x130) {
+ /* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */
+ return 0x69;
+ }
+ }
+ } else if(HAS_SLOT(excWord, UCASE_EXC_FULL_MAPPINGS)) {
+ GET_SLOT_VALUE(excWord, UCASE_EXC_FULL_MAPPINGS, pe, full);
+
+ /* start of full case mapping strings */
+ ++pe;
+
+ /* skip the lowercase result string */
+ pe+=full&UCASE_FULL_LOWER;
+ full=(full>>4)&0xf;
+
+ if(full!=0) {
+ /* set the output pointer to the result string */
+ *pString=pe;
+
+ /* return the string length */
+ return full;
+ }
+ }
+
+ if(HAS_SLOT(excWord, UCASE_EXC_FOLD)) {
+ index=UCASE_EXC_FOLD;
+ } else if(HAS_SLOT(excWord, UCASE_EXC_LOWER)) {
+ index=UCASE_EXC_LOWER;
+ } else {
+ return ~c;
+ }
+ GET_SLOT_VALUE(excWord, index, pe2, result);
+ }
+
+ return (result==c) ? ~result : result;
+}
+
+/* case mapping properties API ---------------------------------------------- */
+
+/* get the UCaseProps singleton, or else its dummy, once and for all */
+static const UCaseProps *
+getCaseProps() {
+ /*
+ * This lazy intialization with double-checked locking (without mutex protection for
+ * the initial check) is transiently unsafe under certain circumstances.
+ * Check the readme and use u_init() if necessary.
+ */
+
+ /* the initial check is performed by the GET_CASE_PROPS() macro */
+ const UCaseProps *csp;
+ UErrorCode errorCode=U_ZERO_ERROR;
+
+ csp=ucase_getSingleton(&errorCode);
+ if(U_FAILURE(errorCode)) {
+ errorCode=U_ZERO_ERROR;
+ csp=ucase_getDummy(&errorCode);
+ if(U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ }
+
+ return csp;
+}
+
+/*
+ * In ICU 3.0, most Unicode properties were loaded from uprops.icu.
+ * ICU 3.2 adds ucase.icu for case mapping properties.
+ * ICU 3.4 adds ubidi.icu for bidi/shaping properties and
+ * removes case/bidi/shaping properties from uprops.icu.
+ *
+ * Loading of uprops.icu was never mutex-protected and required u_init()
+ * for thread safety.
+ * In order to maintain performance for all such properties,
+ * ucase.icu and ubidi.icu are loaded lazily, without mutexing.
+ * u_init() will try to load them for thread safety,
+ * but u_init() will not fail if they are missing.
+ *
+ * uchar.c maintains a tri-state flag for (not loaded/loaded/failed to load)
+ * and an error code for load failure.
+ * Instead, here we try to load at most once.
+ * If it works, we use the resulting singleton object.
+ * If it fails, then we get a dummy object, which always works unless
+ * we are seriously out of memory.
+ * After the first try, we have a never-changing pointer to either the
+ * real singleton or the dummy.
+ *
+ * This method is used in Unicode properties APIs (uchar.h) that
+ * do not have a service object and also do not have an error code parameter.
+ * Other API implementations get the singleton themselves
+ * (with mutexing), store it in the service object, and report errors.
+ */
+#define GET_CASE_PROPS() (gCsp!=NULL ? gCsp : getCaseProps())
+
+/* public API (see uchar.h) */
+
+U_CAPI UBool U_EXPORT2
+u_isULowercase(UChar32 c) {
+ return (UBool)(UCASE_LOWER==ucase_getType(GET_CASE_PROPS(), c));
+}
+
+U_CAPI UBool U_EXPORT2
+u_isUUppercase(UChar32 c) {
+ return (UBool)(UCASE_UPPER==ucase_getType(GET_CASE_PROPS(), c));
+}
+
+/* Transforms the Unicode character to its lower case equivalent.*/
+U_CAPI UChar32 U_EXPORT2
+u_tolower(UChar32 c) {
+ return ucase_tolower(GET_CASE_PROPS(), c);
+}
+
+/* Transforms the Unicode character to its upper case equivalent.*/
+U_CAPI UChar32 U_EXPORT2
+u_toupper(UChar32 c) {
+ return ucase_toupper(GET_CASE_PROPS(), c);
+}
+
+/* Transforms the Unicode character to its title case equivalent.*/
+U_CAPI UChar32 U_EXPORT2
+u_totitle(UChar32 c) {
+ return ucase_totitle(GET_CASE_PROPS(), c);
+}
+
+/* return the simple case folding mapping for c */
+U_CAPI UChar32 U_EXPORT2
+u_foldCase(UChar32 c, uint32_t options) {
+ return ucase_fold(GET_CASE_PROPS(), c, options);
+}
+
+U_CFUNC int32_t U_EXPORT2
+ucase_hasBinaryProperty(UChar32 c, UProperty which) {
+ /* case mapping properties */
+ const UCaseProps *csp=GET_CASE_PROPS();
+ if(csp==NULL) {
+ return FALSE;
+ }
+ switch(which) {
+ case UCHAR_LOWERCASE:
+ return (UBool)(UCASE_LOWER==ucase_getType(csp, c));
+ case UCHAR_UPPERCASE:
+ return (UBool)(UCASE_UPPER==ucase_getType(csp, c));
+ case UCHAR_SOFT_DOTTED:
+ return ucase_isSoftDotted(csp, c);
+ case UCHAR_CASE_SENSITIVE:
+ return ucase_isCaseSensitive(csp, c);
+ default:
+ return FALSE;
+ }
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/ucase.h b/Build/source/libs/icu/icu-xetex/common/ucase.h
new file mode 100644
index 00000000000..1c29482d8fc
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucase.h
@@ -0,0 +1,376 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2004-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: ucase.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004aug30
+* created by: Markus W. Scherer
+*
+* Low-level Unicode character/string case mapping code.
+*/
+
+#ifndef __UCASE_H__
+#define __UCASE_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "uset_imp.h"
+#include "udataswp.h"
+
+U_CDECL_BEGIN
+
+/* library API -------------------------------------------------------------- */
+
+struct UCaseProps;
+typedef struct UCaseProps UCaseProps;
+
+U_CAPI UCaseProps * U_EXPORT2
+ucase_open(UErrorCode *pErrorCode);
+
+U_CAPI UCaseProps * U_EXPORT2
+ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode);
+
+U_CAPI void U_EXPORT2
+ucase_close(UCaseProps *csp);
+
+
+U_CAPI const UCaseProps * U_EXPORT2
+ucase_getSingleton(UErrorCode *pErrorCode);
+
+/**
+ * Get a singleton dummy object, one that works with no real data.
+ * This can be used when the real data is not available.
+ * Using the dummy can reduce checks for available data after an initial failure.
+ */
+U_CAPI const UCaseProps * U_EXPORT2
+ucase_getDummy(UErrorCode *pErrorCode);
+
+
+U_CAPI int32_t U_EXPORT2
+ucase_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void U_EXPORT2
+ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode);
+
+/**
+ * Requires non-NULL locale ID but otherwise does the equivalent of
+ * checking for language codes as if uloc_getLanguage() were called:
+ * Accepts both 2- and 3-letter codes and accepts case variants.
+ */
+U_CFUNC int32_t
+ucase_getCaseLocale(const char *locale, int32_t *locCache);
+
+/**
+ * Bit mask for getting just the options from a string compare options word
+ * that are relevant for case-insensitive string comparison.
+ * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
+ * @internal
+ */
+#define _STRCASECMP_OPTIONS_MASK 0xffff
+
+/**
+ * Bit mask for getting just the options from a string compare options word
+ * that are relevant for case folding (of a single string or code point).
+ * See uchar.h.
+ * @internal
+ */
+#define _FOLD_CASE_OPTIONS_MASK 0xff
+
+/* single-code point functions */
+
+U_CAPI UChar32 U_EXPORT2
+ucase_tolower(const UCaseProps *csp, UChar32 c);
+
+U_CAPI UChar32 U_EXPORT2
+ucase_toupper(const UCaseProps *csp, UChar32 c);
+
+U_CAPI UChar32 U_EXPORT2
+ucase_totitle(const UCaseProps *csp, UChar32 c);
+
+U_CAPI UChar32 U_EXPORT2
+ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options);
+
+/**
+ * Adds all simple case mappings and the full case folding for c to sa,
+ * and also adds special case closure mappings.
+ * c itself is not added.
+ * For example, the mappings
+ * - for s include long s
+ * - for sharp s include ss
+ * - for k include the Kelvin sign
+ */
+U_CFUNC void U_EXPORT2
+ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa);
+
+/**
+ * Maps the string to single code points and adds the associated case closure
+ * mappings.
+ * The string is mapped to code points if it is their full case folding string.
+ * In other words, this performs a reverse full case folding and then
+ * adds the case closure items of the resulting code points.
+ * If the string is found and its closure applied, then
+ * the string itself is added as well as part of its code points' closure.
+ * It must be length>=0.
+ *
+ * @return TRUE if the string was found
+ */
+U_CFUNC UBool U_EXPORT2
+ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa);
+
+/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
+U_CAPI int32_t U_EXPORT2
+ucase_getType(const UCaseProps *csp, UChar32 c);
+
+/** @return same as ucase_getType(), or <0 if c is case-ignorable */
+U_CAPI int32_t U_EXPORT2
+ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c);
+
+U_CAPI UBool U_EXPORT2
+ucase_isSoftDotted(const UCaseProps *csp, UChar32 c);
+
+U_CAPI UBool U_EXPORT2
+ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c);
+
+/* string case mapping functions */
+
+/**
+ * Iterator function for string case mappings, which need to look at the
+ * context (surrounding text) of a given character for conditional mappings.
+ *
+ * The iterator only needs to go backward or forward away from the
+ * character in question. It does not use any indexes on this interface.
+ * It does not support random access or an arbitrary change of
+ * iteration direction.
+ *
+ * The code point being case-mapped itself is never returned by
+ * this iterator.
+ *
+ * @param context A pointer to the iterator's working data.
+ * @param dir If <0 then start iterating backward from the character;
+ * if >0 then start iterating forward from the character;
+ * if 0 then continue iterating in the current direction.
+ * @return Next code point, or <0 when the iteration is done.
+ */
+typedef UChar32 U_CALLCONV
+UCaseContextIterator(void *context, int8_t dir);
+
+/**
+ * Sample struct which may be used by some implementations of
+ * UCaseContextIterator.
+ */
+struct UCaseContext {
+ void *p;
+ int32_t start, index, limit;
+ int32_t cpStart, cpLimit;
+ int8_t dir;
+ int8_t b1, b2, b3;
+};
+typedef struct UCaseContext UCaseContext;
+
+enum {
+ /**
+ * For string case mappings, a single character (a code point) is mapped
+ * either to itself (in which case in-place mapping functions do nothing),
+ * or to another single code point, or to a string.
+ * Aside from the string contents, these are indicated with a single int32_t
+ * value as follows:
+ *
+ * Mapping to self: Negative values (~self instead of -self to support U+0000)
+ *
+ * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
+ *
+ * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
+ * returned. Note that the string result may indeed have zero length.
+ */
+ UCASE_MAX_STRING_LENGTH=0x1f
+};
+
+/**
+ * Get the full lowercase mapping for c.
+ *
+ * @param csp Case mapping properties.
+ * @param c Character to be mapped.
+ * @param iter Character iterator, used for context-sensitive mappings.
+ * See UCaseContextIterator for details.
+ * If iter==NULL then a context-independent result is returned.
+ * @param context Pointer to be passed into iter.
+ * @param pString If the mapping result is a string, then the pointer is
+ * written to *pString.
+ * @param locale Locale ID for locale-dependent mappings.
+ * @param locCache Initialize to 0; may be used to cache the result of parsing
+ * the locale ID for subsequent calls.
+ * Can be NULL.
+ * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
+ *
+ * @see UCaseContextIterator
+ * @see UCASE_MAX_STRING_LENGTH
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+ucase_toFullLower(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache);
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullUpper(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache);
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache);
+
+U_CAPI int32_t U_EXPORT2
+ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
+ const UChar **pString,
+ uint32_t options);
+
+U_CFUNC int32_t U_EXPORT2
+ucase_hasBinaryProperty(UChar32 c, UProperty which);
+
+
+U_CDECL_BEGIN
+
+/**
+ * @internal
+ */
+typedef int32_t U_CALLCONV
+UCaseMapFull(const UCaseProps *csp, UChar32 c,
+ UCaseContextIterator *iter, void *context,
+ const UChar **pString,
+ const char *locale, int32_t *locCache);
+
+U_CDECL_END
+
+/* file definitions --------------------------------------------------------- */
+
+#define UCASE_DATA_NAME "ucase"
+#define UCASE_DATA_TYPE "icu"
+
+/* format "cAsE" */
+#define UCASE_FMT_0 0x63
+#define UCASE_FMT_1 0x41
+#define UCASE_FMT_2 0x53
+#define UCASE_FMT_3 0x45
+
+/* indexes into indexes[] */
+enum {
+ UCASE_IX_INDEX_TOP,
+ UCASE_IX_LENGTH,
+ UCASE_IX_TRIE_SIZE,
+ UCASE_IX_EXC_LENGTH,
+ UCASE_IX_UNFOLD_LENGTH,
+
+ UCASE_IX_MAX_FULL_LENGTH=15,
+ UCASE_IX_TOP=16
+};
+
+/* definitions for 16-bit case properties word ------------------------------ */
+
+/* 2-bit constants for types of cased characters */
+#define UCASE_TYPE_MASK 3
+enum {
+ UCASE_NONE,
+ UCASE_LOWER,
+ UCASE_UPPER,
+ UCASE_TITLE
+};
+
+#define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK)
+
+#define UCASE_SENSITIVE 4
+#define UCASE_EXCEPTION 8
+
+#define UCASE_DOT_MASK 0x30
+enum {
+ UCASE_NO_DOT=0, /* normal characters with cc=0 */
+ UCASE_SOFT_DOTTED=0x10, /* soft-dotted characters with cc=0 */
+ UCASE_ABOVE=0x20, /* "above" accents with cc=230 */
+ UCASE_OTHER_ACCENT=0x30 /* other accent character (0>UCASE_DELTA_SHIFT)
+
+/* case-ignorable uses one of the delta bits, see gencase/store.c */
+#define UCASE_CASE_IGNORABLE 0x40
+
+/* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
+#define UCASE_EXC_SHIFT 4
+#define UCASE_EXC_MASK 0xfff0
+#define UCASE_MAX_EXCEPTIONS 0x1000
+
+/* definitions for 16-bit main exceptions word ------------------------------ */
+
+/* first 8 bits indicate values in optional slots */
+enum {
+ UCASE_EXC_LOWER,
+ UCASE_EXC_FOLD,
+ UCASE_EXC_UPPER,
+ UCASE_EXC_TITLE,
+ UCASE_EXC_4, /* reserved */
+ UCASE_EXC_5, /* reserved */
+ UCASE_EXC_CLOSURE,
+ UCASE_EXC_FULL_MAPPINGS,
+ UCASE_EXC_ALL_SLOTS /* one past the last slot */
+};
+
+/* each slot is 2 uint16_t instead of 1 */
+#define UCASE_EXC_DOUBLE_SLOTS 0x100
+
+/* reserved: exception bits 11..9 */
+
+/* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<csp=ucase_getSingleton(pErrorCode);
+ ucasemap_setLocale(csm, locale, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ uprv_free(csm);
+ return NULL;
+ }
+
+ csm->options=options;
+ return csm;
+}
+
+U_CAPI void U_EXPORT2
+ucasemap_close(UCaseMap *csm) {
+ if(csm!=NULL) {
+#if !UCONFIG_NO_BREAK_ITERATION
+ ubrk_close(csm->iter);
+#endif
+ uprv_free(csm);
+ }
+}
+
+U_CAPI const char * U_EXPORT2
+ucasemap_getLocale(const UCaseMap *csm) {
+ return csm->locale;
+}
+
+U_CAPI uint32_t U_EXPORT2
+ucasemap_getOptions(const UCaseMap *csm) {
+ return csm->options;
+}
+
+U_CAPI void U_EXPORT2
+ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode) {
+ int32_t length;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ length=uloc_getName(locale, csm->locale, (int32_t)sizeof(csm->locale), pErrorCode);
+ if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR || length==sizeof(csm->locale)) {
+ *pErrorCode=U_ZERO_ERROR;
+ /* we only really need the language code for case mappings */
+ length=uloc_getLanguage(locale, csm->locale, (int32_t)sizeof(csm->locale), pErrorCode);
+ }
+ if(length==sizeof(csm->locale)) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ csm->locCache=0;
+ if(U_SUCCESS(*pErrorCode)) {
+ ucase_getCaseLocale(csm->locale, &csm->locCache);
+ } else {
+ csm->locale[0]=0;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode) {
+ csm->options=options;
+}
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_CAPI const UBreakIterator * U_EXPORT2
+ucasemap_getBreakIterator(const UCaseMap *csm) {
+ return csm->iter;
+}
+
+U_CAPI void U_EXPORT2
+ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode) {
+ ubrk_close(csm->iter);
+ csm->iter=iterToAdopt;
+}
+
+#endif
+
+/* UTF-8 string case mappings ----------------------------------------------- */
+
+/* TODO(markus): Move to a new, separate utf8case.c file. */
+
+/* append a full case mapping result, see UCASE_MAX_STRING_LENGTH */
+static U_INLINE int32_t
+appendResult(uint8_t *dest, int32_t destIndex, int32_t destCapacity,
+ int32_t result, const UChar *s) {
+ UChar32 c;
+ int32_t length, destLength;
+ UErrorCode errorCode;
+
+ /* decode the result */
+ if(result<0) {
+ /* (not) original code point */
+ c=~result;
+ length=-1;
+ } else if(result<=UCASE_MAX_STRING_LENGTH) {
+ c=U_SENTINEL;
+ length=result;
+ } else {
+ c=result;
+ length=-1;
+ }
+
+ if(destIndexindex=csc->cpStart;
+ csc->dir=dir;
+ } else if(dir>0) {
+ /* reset for forward iteration */
+ csc->index=csc->cpLimit;
+ csc->dir=dir;
+ } else {
+ /* continue current iteration direction */
+ dir=csc->dir;
+ }
+
+ if(dir<0) {
+ if(csc->startindex) {
+ U8_PREV((const uint8_t *)csc->p, csc->start, csc->index, c);
+ return c;
+ }
+ } else {
+ if(csc->indexlimit) {
+ U8_NEXT((const uint8_t *)csc->p, csc->index, csc->limit, c);
+ return c;
+ }
+ }
+ return U_SENTINEL;
+}
+
+/*
+ * Case-maps [srcStart..srcLimit[ but takes
+ * context [0..srcLength[ into account.
+ */
+static int32_t
+_caseMap(const UCaseMap *csm, UCaseMapFull *map,
+ uint8_t *dest, int32_t destCapacity,
+ const uint8_t *src, UCaseContext *csc,
+ int32_t srcStart, int32_t srcLimit,
+ UErrorCode *pErrorCode) {
+ const UChar *s;
+ UChar32 c, c2;
+ int32_t srcIndex, destIndex;
+ int32_t locCache;
+
+ locCache=csm->locCache;
+
+ /* case mapping loop */
+ srcIndex=srcStart;
+ destIndex=0;
+ while(srcIndexcpStart=srcIndex;
+ U8_NEXT(src, srcIndex, srcLimit, c);
+ csc->cpLimit=srcIndex;
+ if(c<0) {
+ int32_t i=csc->cpStart;
+ while(destIndexcsp, c, utf8_caseContextIterator, csc, &s, csm->locale, &locCache);
+ if((destIndexdestCapacity) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ return destIndex;
+}
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+/*
+ * Internal titlecasing function.
+ */
+static int32_t
+_toTitle(UCaseMap *csm,
+ uint8_t *dest, int32_t destCapacity,
+ const uint8_t *src, UCaseContext *csc,
+ int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ UText utext=UTEXT_INITIALIZER;
+ const UChar *s;
+ UChar32 c;
+ int32_t prev, titleStart, titleLimit, index, destIndex, length;
+ UBool isFirstIndex;
+
+ utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if(csm->iter==NULL) {
+ csm->iter=ubrk_open(UBRK_WORD, csm->locale,
+ NULL, 0,
+ pErrorCode);
+ }
+ ubrk_setUText(csm->iter, &utext, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ utext_close(&utext);
+ return 0;
+ }
+
+ /* set up local variables */
+ destIndex=0;
+ prev=0;
+ isFirstIndex=TRUE;
+
+ /* titlecasing loop */
+ while(previter);
+ } else {
+ index=ubrk_next(csm->iter);
+ }
+ if(index==UBRK_DONE || index>srcLength) {
+ index=srcLength;
+ }
+
+ /*
+ * Unicode 4 & 5 section 3.13 Default Case Operations:
+ *
+ * R3 toTitlecase(X): Find the word boundaries based on Unicode Standard Annex
+ * #29, "Text Boundaries." Between each pair of word boundaries, find the first
+ * cased character F. If F exists, map F to default_title(F); then map each
+ * subsequent character C to default_lower(C).
+ *
+ * In this implementation, segment [prev..index[ into 3 parts:
+ * a) uncased characters (copy as-is) [prev..titleStart[
+ * b) first case letter (titlecase) [titleStart..titleLimit[
+ * c) subsequent characters (lowercase) [titleLimit..index[
+ */
+ if(prevoptions&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCASE_NONE==ucase_getType(csm->csp, c)) {
+ /* Adjust the titlecasing index (titleStart) to the next cased character. */
+ for(;;) {
+ titleStart=titleLimit;
+ if(titleLimit==index) {
+ /*
+ * only uncased characters in [prev..index[
+ * stop with titleStart==titleLimit==index
+ */
+ break;
+ }
+ U8_NEXT(src, titleLimit, index, c);
+ if(UCASE_NONE!=ucase_getType(csm->csp, c)) {
+ break; /* cased letter at [titleStart..titleLimit[ */
+ }
+ }
+ length=titleStart-prev;
+ if(length>0) {
+ if((destIndex+length)<=destCapacity) {
+ uprv_memcpy(dest+destIndex, src+prev, length);
+ }
+ destIndex+=length;
+ }
+ }
+
+ if(titleStartcpStart=titleStart;
+ csc->cpLimit=titleLimit;
+ c=ucase_toFullTitle(csm->csp, c, utf8_caseContextIterator, csc, &s, csm->locale, &csm->locCache);
+ destIndex=appendResult(dest, destIndex, destCapacity, c, s);
+
+ /* lowercase [titleLimit..index[ */
+ if(titleLimitoptions&U_TITLECASE_NO_LOWERCASE)==0) {
+ /* Normal operation: Lowercase the rest of the word. */
+ destIndex+=
+ _caseMap(
+ csm, ucase_toFullLower,
+ dest+destIndex, destCapacity-destIndex,
+ src, csc,
+ titleLimit, index,
+ pErrorCode);
+ } else {
+ /* Optionally just copy the rest of the word unchanged. */
+ length=index-titleLimit;
+ if((destIndex+length)<=destCapacity) {
+ uprv_memcpy(dest+destIndex, src+titleLimit, length);
+ }
+ destIndex+=length;
+ }
+ }
+ }
+ }
+
+ prev=index;
+ }
+
+ if(destIndex>destCapacity) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ utext_close(&utext);
+ return destIndex;
+}
+
+#endif
+
+static int32_t
+utf8_foldCase(const UCaseProps *csp,
+ uint8_t *dest, int32_t destCapacity,
+ const uint8_t *src, int32_t srcLength,
+ uint32_t options,
+ UErrorCode *pErrorCode) {
+ int32_t srcIndex, destIndex;
+
+ const UChar *s;
+ UChar32 c, c2;
+ int32_t start;
+
+ /* case mapping loop */
+ srcIndex=destIndex=0;
+ while(srcIndexdestCapacity) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ return destIndex;
+}
+
+/*
+ * Implement argument checking and buffer handling
+ * for string case mapping as a common function.
+ */
+
+/* common internal function for public API functions */
+
+static int32_t
+caseMap(const UCaseMap *csm,
+ uint8_t *dest, int32_t destCapacity,
+ const uint8_t *src, int32_t srcLength,
+ int32_t toWhichCase,
+ UErrorCode *pErrorCode) {
+ int32_t destLength;
+
+ /* check argument values */
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if( destCapacity<0 ||
+ (dest==NULL && destCapacity>0) ||
+ src==NULL ||
+ srcLength<-1
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* get the string length */
+ if(srcLength==-1) {
+ srcLength=uprv_strlen((const char *)src);
+ }
+
+ /* check for overlapping source and destination */
+ if( dest!=NULL &&
+ ((src>=dest && src<(dest+destCapacity)) ||
+ (dest>=src && dest<(src+srcLength)))
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ destLength=0;
+
+ if(toWhichCase==FOLD_CASE) {
+ destLength=utf8_foldCase(csm->csp, dest, destCapacity, src, srcLength,
+ csm->options, pErrorCode);
+ } else {
+ UCaseContext csc={ NULL };
+
+ csc.p=(void *)src;
+ csc.limit=srcLength;
+
+ if(toWhichCase==TO_LOWER) {
+ destLength=_caseMap(csm, ucase_toFullLower,
+ dest, destCapacity,
+ src, &csc,
+ 0, srcLength,
+ pErrorCode);
+ } else if(toWhichCase==TO_UPPER) {
+ destLength=_caseMap(csm, ucase_toFullUpper,
+ dest, destCapacity,
+ src, &csc,
+ 0, srcLength,
+ pErrorCode);
+ } else /* if(toWhichCase==TO_TITLE) */ {
+#if UCONFIG_NO_BREAK_ITERATION
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+#else
+ /* UCaseMap is actually non-const in toTitle() APIs. */
+ destLength=_toTitle((UCaseMap *)csm, dest, destCapacity,
+ src, &csc, srcLength,
+ pErrorCode);
+#endif
+ }
+ }
+
+ return u_terminateChars((char *)dest, destCapacity, destLength, pErrorCode);
+}
+
+/* public API functions */
+
+U_CAPI int32_t U_EXPORT2
+ucasemap_utf8ToLower(const UCaseMap *csm,
+ char *dest, int32_t destCapacity,
+ const char *src, int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ return caseMap(csm,
+ (uint8_t *)dest, destCapacity,
+ (const uint8_t *)src, srcLength,
+ TO_LOWER, pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucasemap_utf8ToUpper(const UCaseMap *csm,
+ char *dest, int32_t destCapacity,
+ const char *src, int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ return caseMap(csm,
+ (uint8_t *)dest, destCapacity,
+ (const uint8_t *)src, srcLength,
+ TO_UPPER, pErrorCode);
+}
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_CAPI int32_t U_EXPORT2
+ucasemap_utf8ToTitle(UCaseMap *csm,
+ char *dest, int32_t destCapacity,
+ const char *src, int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ return caseMap(csm,
+ (uint8_t *)dest, destCapacity,
+ (const uint8_t *)src, srcLength,
+ TO_TITLE, pErrorCode);
+}
+
+#endif
+
+U_CAPI int32_t U_EXPORT2
+ucasemap_utf8FoldCase(const UCaseMap *csm,
+ char *dest, int32_t destCapacity,
+ const char *src, int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ return caseMap(csm,
+ (uint8_t *)dest, destCapacity,
+ (const uint8_t *)src, srcLength,
+ FOLD_CASE, pErrorCode);
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/ucat.c b/Build/source/libs/icu/icu-xetex/common/ucat.c
new file mode 100644
index 00000000000..5f6feb9d1be
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucat.c
@@ -0,0 +1,76 @@
+/*
+**********************************************************************
+* Copyright (c) 2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: March 19 2003
+* Since: ICU 2.6
+**********************************************************************
+*/
+#include "unicode/ucat.h"
+#include "unicode/ustring.h"
+#include "cstring.h"
+#include "uassert.h"
+
+/* Separator between set_num and msg_num */
+static const char SEPARATOR = '%';
+
+/* Maximum length of a set_num/msg_num key, incl. terminating zero.
+ * Longest possible key is "-2147483648%-2147483648" */
+#define MAX_KEY_LEN (24)
+
+/**
+ * Fill in buffer with a set_num/msg_num key string, given the numeric
+ * values. Numeric values must be >= 0. Buffer must be of length
+ * MAX_KEY_LEN or more.
+ */
+static char*
+_catkey(char* buffer, int32_t set_num, int32_t msg_num) {
+ int32_t i = 0;
+ i = T_CString_integerToString(buffer, set_num, 10);
+ buffer[i++] = SEPARATOR;
+ T_CString_integerToString(buffer+i, msg_num, 10);
+ return buffer;
+}
+
+U_CAPI u_nl_catd U_EXPORT2
+u_catopen(const char* name, const char* locale, UErrorCode* ec) {
+ return (u_nl_catd) ures_open(name, locale, ec);
+}
+
+U_CAPI void U_EXPORT2
+u_catclose(u_nl_catd catd) {
+ ures_close((UResourceBundle*) catd); /* may be NULL */
+}
+
+U_CAPI const UChar* U_EXPORT2
+u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num,
+ const UChar* s,
+ int32_t* len, UErrorCode* ec) {
+
+ char key[MAX_KEY_LEN];
+ const UChar* result;
+
+ if (ec == NULL || U_FAILURE(*ec)) {
+ goto ERROR;
+ }
+
+ result = ures_getStringByKey((const UResourceBundle*) catd,
+ _catkey(key, set_num, msg_num),
+ len, ec);
+ if (U_FAILURE(*ec)) {
+ goto ERROR;
+ }
+
+ return result;
+
+ ERROR:
+ /* In case of any failure, return s */
+ if (len != NULL) {
+ *len = u_strlen(s);
+ }
+ return s;
+}
+
+/*eof*/
diff --git a/Build/source/libs/icu/icu-xetex/common/uchar.c b/Build/source/libs/icu/icu-xetex/common/uchar.c
new file mode 100644
index 00000000000..e71d864bf2a
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/uchar.c
@@ -0,0 +1,979 @@
+/*
+********************************************************************************
+* Copyright (C) 1996-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File UCHAR.C
+*
+* Modification History:
+*
+* Date Name Description
+* 04/02/97 aliu Creation.
+* 4/15/99 Madhu Updated all the function definitions for C Implementation
+* 5/20/99 Madhu Added the function u_getVersion()
+* 8/19/1999 srl Upgraded scripts to Unicode3.0
+* 11/11/1999 weiv added u_isalnum(), cleaned comments
+* 01/11/2000 helena Renamed u_getVersion to u_getUnicodeVersion.
+* 06/20/2000 helena OS/400 port changes; mostly typecast.
+******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uchar.h"
+#include "unicode/uscript.h"
+#include "unicode/udata.h"
+#include "umutex.h"
+#include "cmemory.h"
+#include "ucln_cmn.h"
+#include "utrie.h"
+#include "udataswp.h"
+#include "unormimp.h" /* JAMO_L_BASE etc. */
+#include "uprops.h"
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
+/* dynamically loaded Unicode character properties -------------------------- */
+
+#define UCHAR_HARDCODE_DATA 1
+
+#if UCHAR_HARDCODE_DATA
+
+/* uchar_props_data.c is machine-generated by genprops --csource */
+#include "uchar_props_data.c"
+
+#else
+
+/*
+ * loaded uprops.dat -
+ * for a description of the file format, see icu/source/tools/genprops/store.c
+ */
+static const char DATA_NAME[] = "uprops";
+static const char DATA_TYPE[] = "icu";
+
+static UDataMemory *propsData=NULL;
+static UErrorCode dataErrorCode=U_ZERO_ERROR;
+
+static uint8_t formatVersion[4]={ 0, 0, 0, 0 };
+static UVersionInfo dataVersion={ 0, 0, 0, 0 };
+
+static UTrie propsTrie={ 0 }, propsVectorsTrie={ 0 };
+static const uint32_t *pData32=NULL, *propsVectors=NULL;
+static int32_t countPropsVectors=0, propsVectorsColumns=0;
+
+static int8_t havePropsData=0; /* == 0 -> Data has not been loaded.
+ * < 0 -> Error occured attempting to load data.
+ * > 0 -> Data has been successfully loaded.
+ */
+
+/* index values loaded from uprops.dat */
+static int32_t indexes[UPROPS_INDEX_COUNT];
+
+static UBool U_CALLCONV
+isAcceptable(void *context,
+ const char *type, const char *name,
+ const UDataInfo *pInfo) {
+ if(
+ pInfo->size>=20 &&
+ pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
+ pInfo->charsetFamily==U_CHARSET_FAMILY &&
+ pInfo->dataFormat[0]==0x55 && /* dataFormat="UPro" */
+ pInfo->dataFormat[1]==0x50 &&
+ pInfo->dataFormat[2]==0x72 &&
+ pInfo->dataFormat[3]==0x6f &&
+ pInfo->formatVersion[0]==4 &&
+ pInfo->formatVersion[2]==UTRIE_SHIFT &&
+ pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
+ ) {
+ uprv_memcpy(formatVersion, pInfo->formatVersion, 4);
+ uprv_memcpy(dataVersion, pInfo->dataVersion, 4);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+static UBool U_CALLCONV uchar_cleanup(void)
+{
+ if (propsData) {
+ udata_close(propsData);
+ propsData=NULL;
+ }
+ pData32=NULL;
+ propsVectors=NULL;
+ countPropsVectors=0;
+ uprv_memset(dataVersion, 0, U_MAX_VERSION_LENGTH);
+ dataErrorCode=U_ZERO_ERROR;
+ havePropsData=0;
+
+ return TRUE;
+}
+
+struct UCharProps {
+ UDataMemory *propsData;
+ UTrie propsTrie, propsVectorsTrie;
+ const uint32_t *pData32;
+};
+typedef struct UCharProps UCharProps;
+
+/* open uprops.icu */
+static void
+_openProps(UCharProps *ucp, UErrorCode *pErrorCode) {
+ const uint32_t *p;
+ int32_t length;
+
+ ucp->propsData=udata_openChoice(NULL, DATA_TYPE, DATA_NAME, isAcceptable, NULL, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ ucp->pData32=p=(const uint32_t *)udata_getMemory(ucp->propsData);
+
+ /* unserialize the trie; it is directly after the int32_t indexes[UPROPS_INDEX_COUNT] */
+ length=(int32_t)p[UPROPS_PROPS32_INDEX]*4;
+ length=utrie_unserialize(&ucp->propsTrie, (const uint8_t *)(p+UPROPS_INDEX_COUNT), length-64, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ /* unserialize the properties vectors trie */
+ length=(int32_t)(p[UPROPS_ADDITIONAL_VECTORS_INDEX]-p[UPROPS_ADDITIONAL_TRIE_INDEX])*4;
+ if(length>0) {
+ length=utrie_unserialize(&ucp->propsVectorsTrie, (const uint8_t *)(p+p[UPROPS_ADDITIONAL_TRIE_INDEX]), length, pErrorCode);
+ }
+ if(length<=0 || U_FAILURE(*pErrorCode)) {
+ /*
+ * length==0:
+ * Allow the properties vectors trie to be missing -
+ * also requires propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX]
+ * to be zero so that this trie is never accessed.
+ */
+ uprv_memset(&ucp->propsVectorsTrie, 0, sizeof(ucp->propsVectorsTrie));
+ }
+}
+
+#endif
+
+#if !UCHAR_HARDCODE_DATA
+static int8_t
+uprv_loadPropsData(UErrorCode *pErrorCode) {
+ /* load Unicode character properties data from file if necessary */
+
+ /*
+ * This lazy intialization with double-checked locking (without mutex protection for
+ * haveNormData==0) is transiently unsafe under certain circumstances.
+ * Check the readme and use u_init() if necessary.
+ */
+ if(havePropsData==0) {
+ UCharProps ucp={ NULL };
+
+ if(U_FAILURE(*pErrorCode)) {
+ return havePropsData;
+ }
+
+ /* open the data outside the mutex block */
+ _openProps(&ucp, pErrorCode);
+
+ if(U_SUCCESS(*pErrorCode)) {
+ /* in the mutex block, set the data for this process */
+ umtx_lock(NULL);
+ if(propsData==NULL) {
+ propsData=ucp.propsData;
+ ucp.propsData=NULL;
+ pData32=ucp.pData32;
+ ucp.pData32=NULL;
+ uprv_memcpy(&propsTrie, &ucp.propsTrie, sizeof(propsTrie));
+ uprv_memcpy(&propsVectorsTrie, &ucp.propsVectorsTrie, sizeof(propsVectorsTrie));
+ }
+
+ /* initialize some variables */
+ uprv_memcpy(indexes, pData32, sizeof(indexes));
+
+ /* additional properties */
+ if(indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]!=0) {
+ propsVectors=pData32+indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
+ countPropsVectors=indexes[UPROPS_RESERVED_INDEX]-indexes[UPROPS_ADDITIONAL_VECTORS_INDEX];
+ propsVectorsColumns=indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX];
+ }
+
+ havePropsData=1;
+ umtx_unlock(NULL);
+ } else {
+ dataErrorCode=*pErrorCode;
+ havePropsData=-1;
+ }
+ ucln_common_registerCleanup(UCLN_COMMON_UCHAR, uchar_cleanup);
+
+ /* if a different thread set it first, then close the extra data */
+ udata_close(ucp.propsData); /* NULL if it was set correctly */
+ }
+
+ return havePropsData;
+}
+
+static int8_t
+loadPropsData(void) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ int8_t retVal = uprv_loadPropsData(&errorCode);
+ return retVal;
+}
+
+#endif
+
+/* constants and macros for access to the data ------------------------------ */
+
+/* getting a uint32_t properties word from the data */
+#if UCHAR_HARDCODE_DATA
+
+#define GET_PROPS(c, result) UTRIE_GET16(&propsTrie, c, result);
+
+#else
+
+#define HAVE_DATA (havePropsData>0 || loadPropsData()>0)
+#define GET_PROPS_UNSAFE(c, result) \
+ UTRIE_GET16(&propsTrie, c, result);
+#define GET_PROPS(c, result) \
+ if(HAVE_DATA) { \
+ GET_PROPS_UNSAFE(c, result); \
+ } else { \
+ (result)=0; \
+ }
+
+#endif
+
+U_CFUNC UBool
+uprv_haveProperties(UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return FALSE;
+ }
+#if !UCHAR_HARDCODE_DATA
+ if(havePropsData==0) {
+ uprv_loadPropsData(pErrorCode);
+ }
+ if(havePropsData<0) {
+ *pErrorCode=dataErrorCode;
+ return FALSE;
+ }
+#endif
+ return TRUE;
+}
+
+/* API functions ------------------------------------------------------------ */
+
+/* Gets the Unicode character's general category.*/
+U_CAPI int8_t U_EXPORT2
+u_charType(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (int8_t)GET_CATEGORY(props);
+}
+
+/* Enumerate all code points with their general categories. */
+struct _EnumTypeCallback {
+ UCharEnumTypeRange *enumRange;
+ const void *context;
+};
+
+static uint32_t U_CALLCONV
+_enumTypeValue(const void *context, uint32_t value) {
+ return GET_CATEGORY(value);
+}
+
+static UBool U_CALLCONV
+_enumTypeRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+ /* just cast the value to UCharCategory */
+ return ((struct _EnumTypeCallback *)context)->
+ enumRange(((struct _EnumTypeCallback *)context)->context,
+ start, limit, (UCharCategory)value);
+}
+
+U_CAPI void U_EXPORT2
+u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) {
+ struct _EnumTypeCallback callback;
+
+ if(enumRange==NULL
+#if !UCHAR_HARDCODE_DATA
+ || !HAVE_DATA
+#endif
+ ) {
+ return;
+ }
+
+ callback.enumRange=enumRange;
+ callback.context=context;
+ utrie_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback);
+}
+
+/* Checks if ch is a lower case letter.*/
+U_CAPI UBool U_EXPORT2
+u_islower(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER);
+}
+
+/* Checks if ch is an upper case letter.*/
+U_CAPI UBool U_EXPORT2
+u_isupper(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER);
+}
+
+/* Checks if ch is a title case letter; usually upper case letters.*/
+U_CAPI UBool U_EXPORT2
+u_istitle(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER);
+}
+
+/* Checks if ch is a decimal digit. */
+U_CAPI UBool U_EXPORT2
+u_isdigit(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
+}
+
+U_CAPI UBool U_EXPORT2
+u_isxdigit(UChar32 c) {
+ uint32_t props;
+
+ /* check ASCII and Fullwidth ASCII a-fA-F */
+ if(
+ (c<=0x66 && c>=0x41 && (c<=0x46 || c>=0x61)) ||
+ (c>=0xff21 && c<=0xff46 && (c<=0xff26 || c>=0xff41))
+ ) {
+ return TRUE;
+ }
+
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
+}
+
+/* Checks if the Unicode character is a letter.*/
+U_CAPI UBool U_EXPORT2
+u_isalpha(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0);
+}
+
+U_CAPI UBool U_EXPORT2
+u_isUAlphabetic(UChar32 c) {
+ return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_ALPHABETIC))!=0;
+}
+
+/* Checks if c is a letter or a decimal digit */
+U_CAPI UBool U_EXPORT2
+u_isalnum(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0);
+}
+
+/**
+ * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM.
+ * @internal
+ */
+U_CFUNC UBool
+u_isalnumPOSIX(UChar32 c) {
+ return (UBool)(u_isUAlphabetic(c) || u_isdigit(c));
+}
+
+/* Checks if ch is a unicode character with assigned character type.*/
+U_CAPI UBool U_EXPORT2
+u_isdefined(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)!=0);
+}
+
+/* Checks if the Unicode character is a base form character that can take a diacritic.*/
+U_CAPI UBool U_EXPORT2
+u_isbase(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0);
+}
+
+/* Checks if the Unicode character is a control character.*/
+U_CAPI UBool U_EXPORT2
+u_iscntrl(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0);
+}
+
+U_CAPI UBool U_EXPORT2
+u_isISOControl(UChar32 c) {
+ return (uint32_t)c<=0x9f && (c<=0x1f || c>=0x7f);
+}
+
+/* Some control characters that are used as space. */
+#define IS_THAT_CONTROL_SPACE(c) \
+ (c<=0x9f && ((c>=TAB && c<=CR) || (c>=0x1c && c <=0x1f) || c==NL))
+
+/* Checks if the Unicode character is a space character.*/
+U_CAPI UBool U_EXPORT2
+u_isspace(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c));
+}
+
+U_CAPI UBool U_EXPORT2
+u_isJavaSpaceChar(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0);
+}
+
+/* Checks if the Unicode character is a whitespace character.*/
+U_CAPI UBool U_EXPORT2
+u_isWhitespace(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(
+ ((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
+ c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
+ IS_THAT_CONTROL_SPACE(c)
+ );
+}
+
+U_CAPI UBool U_EXPORT2
+u_isblank(UChar32 c) {
+ if((uint32_t)c<=0x9f) {
+ return c==9 || c==0x20; /* TAB or SPACE */
+ } else {
+ /* Zs */
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR);
+ }
+}
+
+U_CAPI UBool U_EXPORT2
+u_isUWhiteSpace(UChar32 c) {
+ return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_WHITE_SPACE))!=0;
+}
+
+/* Checks if the Unicode character is printable.*/
+U_CAPI UBool U_EXPORT2
+u_isprint(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /* comparing ==0 returns FALSE for the categories mentioned */
+ return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0);
+}
+
+/**
+ * Checks if c is in \p{graph}\p{blank} - \p{cntrl}.
+ * Implements UCHAR_POSIX_PRINT.
+ * @internal
+ */
+U_CFUNC UBool
+u_isprintPOSIX(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /*
+ * The only cntrl character in graph+blank is TAB (in blank).
+ * Here we implement (blank-TAB)=Zs instead of calling u_isblank().
+ */
+ return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c));
+}
+
+U_CAPI UBool U_EXPORT2
+u_isgraph(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /* comparing ==0 returns FALSE for the categories mentioned */
+ return (UBool)((CAT_MASK(props)&
+ (U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
+ ==0);
+}
+
+/**
+ * Checks if c is in
+ * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]
+ * with space=\p{Whitespace} and Control=Cc.
+ * Implements UCHAR_POSIX_GRAPH.
+ * @internal
+ */
+U_CFUNC UBool
+u_isgraphPOSIX(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ /* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
+ /* comparing ==0 returns FALSE for the categories mentioned */
+ return (UBool)((CAT_MASK(props)&
+ (U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
+ ==0);
+}
+
+U_CAPI UBool U_EXPORT2
+u_ispunct(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0);
+}
+
+/* Checks if the Unicode character can start a Unicode identifier.*/
+U_CAPI UBool U_EXPORT2
+u_isIDStart(UChar32 c) {
+ /* same as u_isalpha() */
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_NL_MASK))!=0);
+}
+
+/* Checks if the Unicode character can be a Unicode identifier part other than starting the
+ identifier.*/
+U_CAPI UBool U_EXPORT2
+u_isIDPart(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(
+ (CAT_MASK(props)&
+ (U_GC_ND_MASK|U_GC_NL_MASK|
+ U_GC_L_MASK|
+ U_GC_PC_MASK|U_GC_MC_MASK|U_GC_MN_MASK)
+ )!=0 ||
+ u_isIDIgnorable(c));
+}
+
+/*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/
+U_CAPI UBool U_EXPORT2
+u_isIDIgnorable(UChar32 c) {
+ if(c<=0x9f) {
+ return u_isISOControl(c) && !IS_THAT_CONTROL_SPACE(c);
+ } else {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR);
+ }
+}
+
+/*Checks if the Unicode character can start a Java identifier.*/
+U_CAPI UBool U_EXPORT2
+u_isJavaIDStart(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0);
+}
+
+/*Checks if the Unicode character can be a Java identifier part other than starting the
+ * identifier.
+ */
+U_CAPI UBool U_EXPORT2
+u_isJavaIDPart(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return (UBool)(
+ (CAT_MASK(props)&
+ (U_GC_ND_MASK|U_GC_NL_MASK|
+ U_GC_L_MASK|
+ U_GC_SC_MASK|U_GC_PC_MASK|
+ U_GC_MC_MASK|U_GC_MN_MASK)
+ )!=0 ||
+ u_isIDIgnorable(c));
+}
+
+U_CAPI int32_t U_EXPORT2
+u_charDigitValue(UChar32 c) {
+ uint32_t props;
+ GET_PROPS(c, props);
+
+ if(GET_NUMERIC_TYPE(props)==1) {
+ return GET_NUMERIC_VALUE(props);
+ } else {
+ return -1;
+ }
+}
+
+U_CAPI double U_EXPORT2
+u_getNumericValue(UChar32 c) {
+ uint32_t props, numericType, numericValue;
+ GET_PROPS(c, props);
+ numericType=GET_NUMERIC_TYPE(props);
+
+ if(numericType==0 || numericType>=UPROPS_NT_COUNT) {
+ return U_NO_NUMERIC_VALUE;
+ }
+
+ numericValue=GET_NUMERIC_VALUE(props);
+
+ if(numericType>UPROPS_FRACTION_NUM_SHIFT;
+ denominator=(numericValue&UPROPS_FRACTION_DEN_MASK)+UPROPS_FRACTION_DEN_OFFSET;
+
+ if(numerator==0) {
+ numerator=-1;
+ }
+ return (double)numerator/(double)denominator;
+ } else /* numericType==UPROPS_NT_LARGE */ {
+ /* large value with exponent */
+ double numValue;
+ int32_t mant, exp;
+
+ mant=(int32_t)numericValue>>UPROPS_LARGE_MANT_SHIFT;
+ exp=(int32_t)numericValue&UPROPS_LARGE_EXP_MASK;
+ if(mant==0) {
+ mant=1;
+ exp+=UPROPS_LARGE_EXP_OFFSET_EXTRA;
+ } else if(mant>9) {
+ return U_NO_NUMERIC_VALUE; /* reserved mantissa value */
+ } else {
+ exp+=UPROPS_LARGE_EXP_OFFSET;
+ }
+
+ numValue=mant;
+
+ /* multiply by 10^exp without math.h */
+ while(exp>=4) {
+ numValue*=10000.;
+ exp-=4;
+ }
+ switch(exp) {
+ case 3:
+ numValue*=1000.;
+ break;
+ case 2:
+ numValue*=100.;
+ break;
+ case 1:
+ numValue*=10.;
+ break;
+ case 0:
+ default:
+ break;
+ }
+
+ return numValue;
+ }
+}
+
+/* ICU 3.4: bidi/shaping properties moved to ubidi_props.c */
+
+/* ICU 2.1: u_getCombiningClass() moved to unorm.cpp */
+
+U_CAPI int32_t U_EXPORT2
+u_digit(UChar32 ch, int8_t radix) {
+ int8_t value;
+ if((uint8_t)(radix-2)<=(36-2)) {
+ value=(int8_t)u_charDigitValue(ch);
+ if(value<0) {
+ /* ch is not a decimal digit, try latin letters */
+ if(ch>=0x61 && ch<=0x7A) {
+ value=(int8_t)(ch-0x57); /* ch - 'a' + 10 */
+ } else if(ch>=0x41 && ch<=0x5A) {
+ value=(int8_t)(ch-0x37); /* ch - 'A' + 10 */
+ } else if(ch>=0xFF41 && ch<=0xFF5A) {
+ value=(int8_t)(ch-0xFF37); /* fullwidth ASCII a-z */
+ } else if(ch>=0xFF21 && ch<=0xFF3A) {
+ value=(int8_t)(ch-0xFF17); /* fullwidth ASCII A-Z */
+ }
+ }
+ } else {
+ value=-1; /* invalid radix */
+ }
+ return (int8_t)((value(36-2) || (uint32_t)digit>=(uint32_t)radix) {
+ return 0;
+ } else if(digit<10) {
+ return (UChar32)(0x30+digit);
+ } else {
+ return (UChar32)((0x61-10)+digit);
+ }
+}
+
+/* miscellaneous, and support for uprops.c ---------------------------------- */
+
+U_CAPI void U_EXPORT2
+u_getUnicodeVersion(UVersionInfo versionArray) {
+ if(versionArray!=NULL) {
+ uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH);
+ }
+}
+
+U_CFUNC uint32_t
+u_getUnicodeProperties(UChar32 c, int32_t column) {
+ uint16_t vecIndex;
+
+ if(column==-1) {
+ uint32_t props;
+ GET_PROPS(c, props);
+ return props;
+ } else if(
+#if !UCHAR_HARDCODE_DATA
+ !HAVE_DATA || countPropsVectors==0 ||
+#endif
+ column<0 || column>=propsVectorsColumns
+ ) {
+ return 0;
+ } else {
+ UTRIE_GET16(&propsVectorsTrie, c, vecIndex);
+ return propsVectors[vecIndex+column];
+ }
+}
+
+U_CFUNC int32_t
+uprv_getMaxValues(int32_t column) {
+#if !UCHAR_HARDCODE_DATA
+ if(HAVE_DATA) {
+#endif
+ switch(column) {
+ case 0:
+ return indexes[UPROPS_MAX_VALUES_INDEX];
+ case 2:
+ return indexes[UPROPS_MAX_VALUES_2_INDEX];
+ default:
+ return 0;
+ }
+#if !UCHAR_HARDCODE_DATA
+ } else {
+ return 0;
+ }
+#endif
+}
+
+/*
+ * get Hangul Syllable Type
+ * implemented here so that uchar.c (uhst_addPropertyStarts())
+ * does not depend on uprops.c (u_getIntPropertyValue(c, UCHAR_HANGUL_SYLLABLE_TYPE))
+ */
+U_CFUNC UHangulSyllableType
+uchar_getHST(UChar32 c) {
+ /* purely algorithmic; hardcode known characters, check for assigned new ones */
+ if(c>UPROPS_AGE_SHIFT;
+ versionArray[0]=(uint8_t)(version>>4);
+ versionArray[1]=(uint8_t)(version&0xf);
+ versionArray[2]=versionArray[3]=0;
+ }
+}
+
+U_CAPI UScriptCode U_EXPORT2
+uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return USCRIPT_INVALID_CODE;
+ }
+ if((uint32_t)c>0x10ffff) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return USCRIPT_INVALID_CODE;
+ }
+
+ return (UScriptCode)(u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_MASK);
+}
+
+U_CAPI UBlockCode U_EXPORT2
+ublock_getCode(UChar32 c) {
+ return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT);
+}
+
+/* property starts for UnicodeSet ------------------------------------------- */
+
+/* for Hangul_Syllable_Type */
+U_CFUNC void U_EXPORT2
+uhst_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
+ UChar32 c;
+ int32_t value, value2;
+
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+#if !UCHAR_HARDCODE_DATA
+ if(!HAVE_DATA) {
+ *pErrorCode=dataErrorCode;
+ return;
+ }
+#endif
+
+ /* add code points with hardcoded properties, plus the ones following them */
+
+ /*
+ * Add Jamo type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE.
+ * First, we add fixed boundaries for the blocks of Jamos.
+ * Then we check in loops to see where the current Unicode version
+ * actually stops assigning such Jamos. We start each loop
+ * at the end of the per-Jamo-block assignments in Unicode 4 or earlier.
+ * (These have not changed since Unicode 2.)
+ */
+ sa->add(sa->set, 0x1100);
+ value=U_HST_LEADING_JAMO;
+ for(c=0x115a; c<=0x115f; ++c) {
+ value2=uchar_getHST(c);
+ if(value!=value2) {
+ value=value2;
+ sa->add(sa->set, c);
+ }
+ }
+
+ sa->add(sa->set, 0x1160);
+ value=U_HST_VOWEL_JAMO;
+ for(c=0x11a3; c<=0x11a7; ++c) {
+ value2=uchar_getHST(c);
+ if(value!=value2) {
+ value=value2;
+ sa->add(sa->set, c);
+ }
+ }
+
+ sa->add(sa->set, 0x11a8);
+ value=U_HST_TRAILING_JAMO;
+ for(c=0x11fa; c<=0x11ff; ++c) {
+ value2=uchar_getHST(c);
+ if(value!=value2) {
+ value=value2;
+ sa->add(sa->set, c);
+ }
+ }
+
+ /* Add Hangul type boundaries for UCHAR_HANGUL_SYLLABLE_TYPE. */
+ for(c=HANGUL_BASE; c<(HANGUL_BASE+HANGUL_COUNT); c+=JAMO_T_COUNT) {
+ sa->add(sa->set, c);
+ sa->add(sa->set, c+1);
+ }
+ sa->add(sa->set, c);
+}
+
+static UBool U_CALLCONV
+_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 limit, uint32_t value) {
+ /* add the start code point to the USet */
+ const USetAdder *sa=(const USetAdder *)context;
+ sa->add(sa->set, start);
+ return TRUE;
+}
+
+#define USET_ADD_CP_AND_NEXT(sa, cp) sa->add(sa->set, cp); sa->add(sa->set, cp+1)
+
+U_CFUNC void U_EXPORT2
+uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+#if !UCHAR_HARDCODE_DATA
+ if(!HAVE_DATA) {
+ *pErrorCode=dataErrorCode;
+ return;
+ }
+#endif
+
+ /* add the start code point of each same-value range of the main trie */
+ utrie_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa);
+
+ /* add code points with hardcoded properties, plus the ones following them */
+
+ /* add for u_isblank() */
+ USET_ADD_CP_AND_NEXT(sa, TAB);
+
+ /* add for IS_THAT_CONTROL_SPACE() */
+ sa->add(sa->set, CR+1); /* range TAB..CR */
+ sa->add(sa->set, 0x1c);
+ sa->add(sa->set, 0x1f+1);
+ USET_ADD_CP_AND_NEXT(sa, NL);
+
+ /* add for u_isIDIgnorable() what was not added above */
+ sa->add(sa->set, DEL); /* range DEL..NBSP-1, NBSP added below */
+ sa->add(sa->set, HAIRSP);
+ sa->add(sa->set, RLM+1);
+ sa->add(sa->set, INHSWAP);
+ sa->add(sa->set, NOMDIG+1);
+ USET_ADD_CP_AND_NEXT(sa, ZWNBSP);
+
+ /* add no-break spaces for u_isWhitespace() what was not added above */
+ USET_ADD_CP_AND_NEXT(sa, NBSP);
+ USET_ADD_CP_AND_NEXT(sa, FIGURESP);
+ USET_ADD_CP_AND_NEXT(sa, NNBSP);
+
+ /* add for u_digit() */
+ sa->add(sa->set, U_a);
+ sa->add(sa->set, U_z+1);
+ sa->add(sa->set, U_A);
+ sa->add(sa->set, U_Z+1);
+ sa->add(sa->set, U_FW_a);
+ sa->add(sa->set, U_FW_z+1);
+ sa->add(sa->set, U_FW_A);
+ sa->add(sa->set, U_FW_Z+1);
+
+ /* add for u_isxdigit() */
+ sa->add(sa->set, U_f+1);
+ sa->add(sa->set, U_F+1);
+ sa->add(sa->set, U_FW_f+1);
+ sa->add(sa->set, U_FW_F+1);
+
+ /* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */
+ sa->add(sa->set, WJ); /* range WJ..NOMDIG */
+ sa->add(sa->set, 0xfff0);
+ sa->add(sa->set, 0xfffb+1);
+ sa->add(sa->set, 0xe0000);
+ sa->add(sa->set, 0xe0fff+1);
+
+ /* add for UCHAR_GRAPHEME_BASE and others */
+ USET_ADD_CP_AND_NEXT(sa, CGJ);
+}
+
+U_CFUNC void U_EXPORT2
+upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+#if !UCHAR_HARDCODE_DATA
+ if(!HAVE_DATA) {
+ *pErrorCode=dataErrorCode;
+ return;
+ }
+#endif
+
+ /* add the start code point of each same-value range of the properties vectors trie */
+ if(propsVectorsColumns>0) {
+ /* if propsVectorsColumns==0 then the properties vectors trie may not be there at all */
+ utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
+ }
+}
diff --git a/Build/source/libs/icu/icu-xetex/common/uchar_props_data.c b/Build/source/libs/icu/icu-xetex/common/uchar_props_data.c
new file mode 100644
index 00000000000..aedc01dbdca
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/uchar_props_data.c
@@ -0,0 +1,2155 @@
+/*
+ * Copyright (C) 1999-2007, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *
+ * file name: uchar_props_data.c
+ *
+ * machine-generated on: 2006-06-13
+ */
+
+static const UVersionInfo formatVersion={4,0,5,2};
+
+static const UVersionInfo dataVersion={5,0,0,0};
+
+static const uint16_t propsTrie_index[13440]={
+0x2a8,0x2b0,0x2b8,0x2c0,0x2c8,0x2d0,0x2d8,0x2e0,0x2e8,0x2ea,0x2f0,0x2f3,0x2fb,0x303,0x30b,0x313,
+0x2e8,0x319,0x321,0x325,0x328,0x32e,0x336,0x33e,0x346,0x346,0x346,0x34a,0x352,0x35a,0x35f,0x365,
+0x36d,0x371,0x325,0x2e8,0x379,0x2e8,0x381,0x2e8,0x385,0x38a,0x38f,0x397,0x39d,0x3a2,0x3aa,0x3b0,
+0x3b8,0x3c0,0x3c8,0x3d0,0x3d5,0x3d5,0x3d8,0x3e0,0x3e8,0x3ed,0x3f3,0x3f8,0x3d5,0x400,0x408,0x40e,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x416,0x418,0x420,0x428,0x430,0x436,0x43e,0x446,
+0x44e,0x454,0x45c,0x464,0x46c,0x472,0x47a,0x482,0x430,0x48a,0x492,0x49a,0x4a2,0x4aa,0x4b2,0x4b9,
+0x4c1,0x4c7,0x4cf,0x4d7,0x4df,0x4e5,0x4ed,0x4f5,0x4df,0x4fd,0x505,0x4d7,0x50d,0x514,0x51c,0x524,
+0x52c,0x530,0x538,0x2a0,0x540,0x548,0x550,0x2a0,0x558,0x560,0x568,0x56e,0x576,0x57d,0x585,0x2a0,
+0x3d5,0x58d,0x595,0x2a0,0x2a0,0x36d,0x59d,0x5a1,0x3d5,0x3d5,0x5a9,0x3d5,0x3d5,0x5b1,0x3d5,0x5b3,
+0x3d5,0x3d5,0x5bb,0x3d5,0x5c3,0x5c7,0x5cf,0x3d5,0x5d5,0x3d5,0x5db,0x5e3,0x5eb,0x3d5,0x3d5,0x5f3,
+0x52c,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x5fb,0x603,0x3d5,0x3d5,0x60b,0x613,0x61b,0x623,0x62b,0x3d5,0x633,0x63b,0x643,
+0x64b,0x3d5,0x653,0x655,0x3d5,0x65d,0x2a0,0x2a0,0x665,0x66d,0x675,0x67a,0x3d5,0x682,0x68a,0x692,
+0x69a,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x6a2,0x6a5,0x6ad,0x6b5,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x325,0x6bd,0x6c0,0x6c8,0x6cf,0x6c0,0x6d7,0x6da,
+0x2e8,0x2e8,0x2e8,0x2e8,0x6e2,0x2e8,0x2e8,0x6ea,0x6f2,0x6fa,0x702,0x70a,0x712,0x716,0x71e,0x726,
+0x72e,0x736,0x73e,0x746,0x74e,0x756,0x75c,0x764,0x76c,0x774,0x77c,0x784,0x78c,0x794,0x799,0x79f,
+0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7ac,0x7b4,0x692,0x7b7,0x7bf,0x7c6,0x7cb,0x7d3,
+0x692,0x7db,0x7e3,0x7eb,0x7ee,0x692,0x692,0x7f5,0x692,0x692,0x692,0x692,0x692,0x7fd,0x805,0x807,
+0x692,0x692,0x692,0x80f,0x813,0x81b,0x2a0,0x2a0,0x823,0x829,0x82e,0x836,0x83e,0x844,0x84c,0x853,
+0x692,0x692,0x692,0x692,0x692,0x692,0x692,0x692,0x7a4,0x7a4,0x7a4,0x7a4,0x85b,0x7a4,0x862,0x869,
+0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x7a4,0x871,0x879,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x36d,0x881,0x885,0x88d,0x2e8,0x2e8,0x2e8,0x895,0x325,0x89d,0x3d5,0x8a4,0x8ac,0x8b4,0x8b4,0x2a0,
+0x8bc,0x2a0,0x2a0,0x2a0,0x8c4,0x692,0x692,0x8cb,0x692,0x692,0x692,0x692,0x692,0x692,0x8d3,0x8d9,
+0x8e1,0x8e9,0x52c,0x3d5,0x8f1,0x8f9,0x3d5,0x8fb,0x52b,0x903,0x3d5,0x3d5,0x908,0x655,0x90e,0x661,
+0x916,0x91e,0x925,0x692,0x91e,0x92d,0x692,0x916,0x692,0x692,0x692,0x692,0x692,0x692,0x692,0x692,
+0xc64,0x3d5,0x3d5,0x3d5,0xbfc,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0xc6a,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc84,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xbb3,0x692,0x692,
+0xbdc,0x3d5,0xc99,0x3d5,0xc01,0xcde,0xcb1,0xc17,0xc62,0x3d5,0x3d5,0xccd,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xce6,0x3d5,0xced,0xc07,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xcb9,0x3d5,0x3d5,0x3d5,0xc1f,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc42,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xbe0,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0xbe7,0x3d5,0x3d5,0x3d5,0xca1,0xbee,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xcbd,0x3d5,0x3d5,0xc95,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc88,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xca9,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0xcd2,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0xc49,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0xcda,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc0c,0x3d5,0x3d5,0x3d5,0xc11,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0xc79,0xc7d,0x3d5,0x3d5,0x3d5,0xbd4,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x654,0x2a0,0x2a0,
+0x935,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x93b,0x692,0x7db,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x943,0x94b,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x953,0x95b,0x3d5,0x963,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xbbb,0x2a0,0x2a0,
+0xcf5,0xcf8,0xd00,0xd07,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0xd0f,0x2a0,0xd17,0xd18,0xd17,0xd18,
+0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,
+0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x96b,0x3d5,0x971,0x3d5,0x3d5,0x5b3,0x2a0,0x979,0x981,0x989,0x3d5,0x3d5,0x3f7,0x991,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x996,0x661,0x3d5,0x99e,0x3d5,0x9a4,0x9a8,
+0x9b0,0x9b8,0x9bf,0x9c7,0x3d5,0x3d5,0x3d5,0x9cd,0x9d5,0x2b8,0x9dd,0x9e5,0x9ea,0x9f2,0x9fa,0xa02,
+0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,
+0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,0xbc3,
+0xa0a,0xa11,0xa19,0x2a0,0x3d5,0x3d5,0x3d5,0xa21,0xa29,0xa31,0xa39,0xa41,0xa48,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x9f2,0xa50,0xa58,0x2a0,0xa60,0x3d5,0xa68,0x2a0,
+0x36d,0xa70,0xa74,0x3d5,0x417,0xa7c,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xa84,0xa87,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0xa8f,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xa97,0xa9e,0xaa6,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xaae,0x2a0,0x2a0,0x2a0,0x2a0,
+0xab6,0xabe,0xac6,0xace,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x692,0x692,0x692,0x692,0x692,0x692,0x692,0x8d3,0x692,0xad6,0x692,0xadd,0xae5,0xaeb,0xaef,0x2a0,
+0x692,0x692,0xaf7,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x692,0x692,0xaff,0xb07,0x2a0,0x2a0,0x2a0,0x2a0,
+0xb0f,0xb16,0xb1b,0xb21,0xb29,0xb31,0xb39,0xb13,0xb41,0xb49,0xb51,0xb56,0xb28,0xb0f,0xb16,0xb12,
+0xb21,0xb5e,0xb10,0xb61,0xb13,0xb69,0xb71,0xb79,0xb80,0xb6c,0xb74,0xb7c,0xb83,0xb6f,0xb8b,0xb93,
+0xc90,0x3d5,0x3d5,0xc50,0x3d5,0x3d5,0x3d5,0xc58,0x3d5,0xc72,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xbf4,0x3d5,0x3d5,0xcc5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc25,0xc2d,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc11,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc34,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0xc3b,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0xc5d,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x8ac,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,0x3d5,
+0x417,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xb9b,0xba3,0xba3,0xba3,0x2a0,0x2a0,0x2a0,0x2a0,0x346,0x346,0x346,0x346,0x346,0x346,0x346,0xbab,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,
+0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcb,0xbcc,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,
+0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,
+0xc,0x17,0x17,0x17,0x19,0x17,0x17,0x17,0x14,0x15,0x17,0x18,0x17,0x13,0x17,0x17,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,0x18,0x18,0x18,0x17,
+0x17,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,0x14,0x17,0x15,0x1a,0x16,
+0x1a,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,0x14,0x18,0x15,0x18,0xf,
+0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,
+0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,
+0xc,0x17,0x19,0x19,0x19,0x19,0x1b,0x1b,0x1a,0x1b,2,0x1c,0x18,0x10,0x1b,0x1a,
+0x1b,0x18,0x24b,0x34b,0x1a,2,0x1b,0x17,0x1a,0x14b,2,0x1d,0xa8b,0x88b,0x1a8b,0x17,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,0x18,1,1,1,1,1,1,1,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,0x18,2,2,2,2,2,2,2,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
+2,1,2,1,2,1,2,1,2,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,1,1,2,1,2,1,2,2,2,1,1,2,
+1,2,1,1,2,1,1,1,2,2,1,1,1,1,2,1,
+1,2,1,1,1,2,2,2,1,1,2,1,1,2,1,2,
+1,2,1,1,2,1,2,2,1,2,1,1,2,1,1,1,
+2,1,2,1,1,2,2,5,1,2,2,2,5,5,5,5,
+1,3,2,1,3,2,1,3,2,1,2,1,2,1,2,1,
+2,1,2,1,2,1,2,1,2,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,2,1,3,2,
+1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,2,2,2,2,2,2,1,1,
+2,1,1,2,2,1,2,1,1,1,1,2,1,2,1,2,
+1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,5,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,4,4,4,4,4,4,4,4,
+4,4,4,4,4,4,4,4,4,4,0x1a,0x1a,0x1a,0x1a,4,4,
+4,4,4,4,4,4,4,4,4,4,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,
+0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,4,4,4,4,4,0x1a,0x1a,0x1a,
+0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,4,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,
+0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,6,0,0,0,0,0x1a,0x1a,0,0,
+0,0,4,2,2,2,0x17,0,0,0,0,0,0x1a,0x1a,1,0x17,
+1,1,1,0,1,0,1,1,2,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,
+1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,0,2,2,1,1,
+1,2,2,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,2,2,2,2,1,2,0x18,1,2,1,1,2,
+2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,1,2,0x1b,6,6,6,6,0,7,7,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,1,1,2,1,2,1,2,1,2,1,2,1,
+2,1,2,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,0,0,4,0x17,0x17,0x17,0x17,0x17,0x17,0,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,0,0x17,0x13,0,
+0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,0x17,6,0x17,6,6,0x17,6,6,0x17,6,
+0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,
+5,5,5,0x17,0x17,0,0,0,0,0,0,0,0,0,0,0,
+0x10,0x10,0x10,0x10,0,0,0,0,0,0,0,0x19,0x17,0x17,0x1b,0x1b,
+6,6,6,6,6,6,0,0,0,0,0,0x17,0,0,0x17,0x17,
+0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0,
+4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,0x17,0x17,5,5,
+6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x17,5,6,6,6,6,6,6,6,0x10,7,6,
+6,6,6,6,6,4,4,6,6,0x1b,6,6,6,6,5,5,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,5,5,5,0x1b,0x1b,5,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0,0x10,
+5,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,0,0,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,
+6,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,6,6,6,6,6,6,6,6,6,4,4,0x1b,0x17,
+0x17,0x17,4,0,0,0,0,0,0,6,6,8,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0,0,6,5,8,8,
+8,6,6,6,6,6,6,6,6,8,8,8,8,6,0,0,
+5,6,6,6,6,0,0,0,5,5,5,5,5,5,5,5,
+5,5,6,6,0x17,0x17,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,
+0x17,0,0,0,0,0,0,0,0,0,0,5,5,5,5,5,
+0,6,8,8,0,5,5,5,5,5,5,5,5,0,0,5,
+5,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0,5,5,5,5,5,5,5,0,5,0,0,0,5,5,
+5,5,0,0,6,5,8,8,8,6,6,6,6,0,0,8,
+8,0,0,8,8,6,5,0,0,0,0,0,0,0,0,8,
+0,0,0,0,5,5,0,5,5,5,6,6,0,0,0x29,0x129,
+0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,5,5,0x19,0x19,0x16b,0x26b,0x36b,0x46b,
+0xb,0x106b,0x1b,0,0,0,0,0,0,6,6,8,0,5,5,5,
+5,5,5,0,0,0,0,5,5,0,0,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0,5,5,5,5,5,5,
+5,0,5,5,0,5,5,0,5,5,0,0,6,0,8,8,
+8,6,6,0,0,0,0,6,6,0,0,6,6,6,0,0,
+0,0,0,0,0,0,0,0,0,5,5,5,5,0,5,0,
+0,0,0,0,0,0,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,
+6,6,5,5,5,0,0,0,0,0,0,0,0,0,0,0,
+0,6,6,8,0,5,5,5,5,5,5,5,5,5,0,5,
+5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0,5,5,5,5,5,5,5,0,5,5,0,5,5,5,
+5,5,0,0,6,5,8,8,8,6,6,6,6,6,0,6,
+6,8,0,8,8,6,0,0,5,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,5,5,6,6,0,0,0x29,0x129,
+0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0,0x19,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,
+5,0,5,5,5,5,5,5,5,0,5,5,0,5,5,5,
+5,5,0,0,6,5,8,6,8,6,6,6,0,0,0,8,
+8,0,0,8,8,6,0,0,0,0,0,0,0,0,6,8,
+0,0,0,0,5,5,0,5,5,5,0,0,0,0,0x29,0x129,
+0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x1b,5,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,6,5,0,5,5,5,
+5,5,5,0,0,0,5,5,5,0,5,5,5,5,0,0,
+0,5,5,0,5,0,5,5,0,0,0,5,5,0,0,0,
+5,5,5,0,0,0,5,5,5,5,5,5,5,5,5,5,
+5,5,0,0,0,0,8,8,6,8,8,0,0,0,8,8,
+8,0,8,8,8,6,0,0,0,0,0,0,0,0,0,8,
+0,0,0,0,0,0,0,0,0,0,0x29,0x129,0x229,0x329,0x429,0x529,
+0x629,0x729,0x829,0x929,0xa6b,0x646b,0x11ab,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x19,0x1b,0,
+0,0,0,0,0,8,8,8,0,5,5,5,5,5,5,5,
+5,0,5,5,5,0,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,0,5,5,5,5,5,5,5,5,5,5,
+0,5,5,5,5,5,0,0,0,0,6,6,6,8,8,8,
+8,0,6,6,6,0,6,6,6,6,0,0,0,0,0,0,
+0,6,6,0,0,0,0,0,0,0,0,0,5,5,0,0,
+0,0,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,
+0,5,5,5,5,5,5,5,5,0,5,5,5,0,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,0,5,5,
+5,5,5,5,5,5,5,5,0,5,5,5,5,5,0,0,
+6,5,8,6,8,8,8,8,8,0,6,8,8,0,8,8,
+6,6,0,0,0,0,0,0,0,8,8,0,0,0,0,0,
+0,0,5,0,5,5,6,6,0,0,0x29,0x129,0x229,0x329,0x429,0x529,
+0x629,0x729,0x829,0x929,0,0x1b,0x1b,0,0,0,0,0,0,0,0,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,0,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,
+0,0,8,8,8,6,6,6,0,0,8,8,8,0,8,8,
+8,6,0,0,0,0,0,0,0,0,0,8,0,0,0,0,
+0,0,0,0,0,0,8,8,0,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,0,0,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0,5,5,5,5,5,5,5,5,5,0,5,0,0,
+5,5,5,5,5,5,5,0,0,0,6,0,0,0,0,8,
+8,8,6,6,6,0,6,0,8,8,8,8,8,8,8,8,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,8,8,0x17,0,0,0,0,0,0,0,0,0,0,0,
+0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,6,5,5,6,6,6,6,6,6,6,0,0,0,0,0x19,
+5,5,5,5,5,5,4,6,6,6,6,6,6,6,6,0x17,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,0,0,0,0,
+0,5,5,0,5,0,0,5,5,0,5,0,0,5,0,0,
+0,0,0,0,5,5,5,5,0,5,5,5,5,5,5,5,
+0,5,5,5,0,5,0,5,0,0,5,5,0,5,5,5,
+5,6,5,5,6,6,6,6,6,6,0,6,6,5,0,0,
+5,5,5,5,5,0,4,0,6,6,6,6,6,6,0,0,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0,0,5,5,0,0,
+5,0x1b,0x1b,0x1b,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
+0x17,0x17,0x17,0x1b,0x1b,0x1b,0x1b,0x1b,6,6,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x88b,0x188b,0x288b,0x388b,0x488b,0x588b,
+0x688b,0x788b,0x888b,0x8b,0x1b,6,0x1b,6,0x1b,6,0x14,0x15,0x14,0x15,8,8,
+5,5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,0,0,0,0,0,0,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,8,6,6,6,6,6,0x17,6,6,
+5,5,5,5,0,0,0,0,6,6,6,6,6,6,6,6,
+0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+6,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,6,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0,0,0x1b,0x17,0x17,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,5,5,0,5,5,5,5,5,0,5,5,0,
+8,6,6,6,6,8,6,0,0,0,6,6,8,6,0,0,
+0,0,0,0,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,
+0x17,0x17,0x17,0x17,5,5,5,5,5,5,8,8,6,6,0,0,
+0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0x17,
+4,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0,
+0,0,0,5,5,5,5,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,0,5,5,5,5,0,0,5,5,5,5,
+5,5,5,0,5,0,5,5,5,5,0,0,5,5,5,5,
+5,5,5,5,5,0,5,5,5,5,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,0,5,5,
+5,5,0,0,5,5,5,5,5,5,5,0,5,0,5,5,
+5,5,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,0,5,5,5,5,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0,0,0,0,6,0x1b,0x17,0x17,0x17,
+0x17,0x17,0x17,0x17,0x17,0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,0x84b,0x94b,0xa6b,0x146b,
+0x1e6b,0x286b,0x326b,0x3c6b,0x466b,0x506b,0x5a6b,0x646b,0x12ab,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0x17,0x17,5,5,5,5,5,
+5,5,5,0,0,0,0,0,0,0,0,0,0xc,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0x14,0x15,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,0x17,0x17,0x17,0x116a,0x126a,0x136a,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0,5,5,5,5,6,6,
+6,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,
+6,0x17,0x17,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0,5,5,5,0,6,6,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x10,0x10,8,6,6,6,6,6,6,6,8,8,8,8,8,8,
+8,8,6,8,8,6,6,6,6,6,6,6,6,6,6,6,
+0x17,0x17,0x17,4,0x17,0x17,0x17,0x19,5,6,0,0,0x29,0x129,0x229,0x329,
+0x429,0x529,0x629,0x729,0x829,0x929,0,0,0,0,0,0,0x6b,0x16b,0x26b,0x36b,
+0x46b,0x56b,0x66b,0x76b,0x86b,0x96b,0,0,0,0,0,0,0x17,0x17,0x17,0x17,
+0x17,0x17,0x13,0x17,0x17,0x17,0x17,6,6,6,0xc,0,0x29,0x129,0x229,0x329,
+0x429,0x529,0x629,0x729,0x829,0x929,0,0,0,0,0,0,5,5,5,4,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,6,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0,0,0,6,6,6,8,8,8,8,6,6,8,8,8,
+0,0,0,0,8,8,6,8,8,8,8,8,8,6,6,6,
+0,0,0,0,0x1b,0,0,0,0x17,0x17,0x29,0x129,0x229,0x329,0x429,0x529,
+0x629,0x729,0x829,0x929,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0,0,5,5,5,5,5,0,0,0,
+0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,
+5,5,0,0,0,0,0,0,8,8,8,8,8,8,8,8,
+8,8,8,8,8,8,8,8,8,5,5,5,5,5,5,5,
+8,8,0,0,0,0,0,0,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,
+0x829,0x929,0,0,0,0,0x17,0x17,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,
+6,8,8,8,0,0,0x17,0x17,6,6,6,6,8,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,6,8,6,6,6,6,6,8,
+6,8,8,8,8,8,6,8,8,5,5,5,5,5,5,5,
+0,0,0,0,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,
+0x17,0x17,0x17,0x17,0x17,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,6,
+6,6,6,6,6,6,6,6,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,
+4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,4,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,4,4,4,4,4,6,6,6,6,
+6,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,6,6,1,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,2,2,
+2,2,2,2,0,0,0,0,1,2,1,2,1,2,1,2,
+1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,
+1,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,
+1,1,1,1,1,1,1,1,2,2,2,2,2,2,0,0,
+1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,
+1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,
+1,1,1,1,1,1,1,1,2,2,2,2,2,2,0,0,
+1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,
+0,1,0,1,0,1,0,1,2,2,2,2,2,2,2,2,
+1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,0,0,2,2,2,2,2,2,2,2,
+3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,
+3,3,3,3,3,3,3,3,2,2,2,2,2,0,2,2,
+1,1,1,1,3,0x1a,2,0x1a,0x1a,0x1a,2,2,2,0,2,2,
+1,1,1,1,3,0x1a,0x1a,0x1a,2,2,2,2,0,0,2,2,
+1,1,1,1,0,0x1a,0x1a,0x1a,2,2,2,2,2,2,2,2,
+1,1,1,1,1,0x1a,0x1a,0x1a,0,0,2,2,2,0,2,2,
+1,1,1,1,3,0x1a,0x1a,0,0xc,0xc,0xc,0xc,0xc,0xc,0xc,0xc,
+0xc,0xc,0xc,0x10,0x10,0x10,0x10,0x10,0x13,0x13,0x13,0x13,0x13,0x13,0x17,0x17,
+0x1c,0x1d,0x14,0x1c,0x1c,0x1d,0x14,0x1c,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
+0xd,0xe,0x10,0x10,0x10,0x10,0x10,0xc,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
+0x17,0x1c,0x1d,0x17,0x17,0x17,0x17,0x16,0x16,0x17,0x17,0x17,0x18,0x14,0x15,0x17,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x18,0x17,0x16,0x17,0x17,0x17,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0xc,0x10,0x10,0x10,0x10,0,0,0,0,
+0,0,0x10,0x10,0x10,0x10,0x10,0x10,0x4b,2,0,0,0x44b,0x54b,0x64b,0x74b,
+0x84b,0x94b,0x18,0x18,0x18,0x14,0x15,2,0x4b,0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,
+0x84b,0x94b,0x18,0x18,0x18,0x14,0x15,0,4,4,4,4,4,0,0,0,
+0,0,0,0,0,0,0,0,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,
+0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,
+7,6,7,7,7,6,6,6,6,6,6,6,6,6,6,6,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x1b,0x1b,1,0x1b,0x1b,0x1b,0x1b,1,0x1b,0x1b,2,1,1,1,2,2,
+1,1,1,2,0x1b,1,0x1b,0x1b,0x1b,1,1,1,1,1,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,1,0x1b,1,0x1b,1,0x1b,1,1,1,1,0x1b,2,
+1,1,1,1,2,5,5,5,5,2,0x1b,0x1b,2,2,1,1,
+0x18,0x18,0x18,0x18,0x18,1,2,2,2,2,0x1b,0x18,0x1b,0x1b,2,0,
+0,0,0,0x98b,0x118b,0xb8b,0x138b,0x1b8b,0x238b,0xc8b,0x2c8b,0xe8b,0x1e8b,0x2e8b,0x3e8b,0x16b,
+0x16a,0x26a,0x36a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,0xa6a,0xb6a,0xc6a,0x326a,0x646a,0x50aa,0x11aa,
+0x16a,0x26a,0x36a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,0xa6a,0xb6a,0xc6a,0x326a,0x646a,0x50aa,0x11aa,
+0x11aa,0x51aa,0x12aa,1,2,0,0,0,0,0,0,0,0,0,0,0,
+0x18,0x18,0x18,0x18,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x18,0x1b,0x1b,0x1b,0x1b,
+0x18,0x1b,0x1b,0x18,0x1b,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x18,0x18,0x1b,0x1b,0x18,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x18,0x18,0x18,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x18,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x14,0x15,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x18,0x18,0x18,0x18,0x18,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x14b,0x24b,0x34b,0x44b,
+0x54b,0x64b,0x74b,0x84b,0x94b,0xa6b,0xb6b,0xc6b,0xd6b,0xe6b,0xf6b,0x106b,0x116b,0x126b,0x136b,0x146b,
+0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,0x84b,0x94b,0xa6b,0xb6b,0xc6b,0xd6b,0xe6b,0xf6b,0x106b,
+0x116b,0x126b,0x136b,0x146b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x4b,0xb6b,
+0xc6b,0xd6b,0xe6b,0xf6b,0x106b,0x116b,0x126b,0x136b,0x146b,0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,
+0x84b,0x94b,0xa6b,0x4b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x18,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,
+0x1b,0,0x1b,0x1b,0x1b,0x1b,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0,0x1b,0,0x1b,0x1b,0x1b,0x1b,0,0,0,0x1b,0,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14b,0x24b,
+0x34b,0x44b,0x54b,0x64b,0x74b,0x84b,0x94b,0xa6b,0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,0x84b,
+0x94b,0xa6b,0x14b,0x24b,0x34b,0x44b,0x54b,0x64b,0x74b,0x84b,0x94b,0xa6b,0x1b,0,0,0,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,
+0x18,0x18,0x18,0x18,0x18,0x14,0x15,0x18,0x18,0x18,0x18,0,0,0,0,0,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x14,0x15,0x14,0x15,0x14,0x15,0,0,0,0,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x14,
+0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,
+0x15,0x14,0x15,0x14,0x15,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x14,0x15,0x14,0x15,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x14,0x15,0x18,0x18,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,
+0,0,0,0,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,0,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,0,1,2,1,1,1,2,2,1,2,1,2,1,
+2,0,0,0,0,0,0,0,2,1,2,2,0,0,0,0,
+0,0,0,0,1,2,1,2,2,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0x17,0x17,0x17,
+0x17,0x88b,0x17,0x17,2,2,2,2,2,2,0,0,0,0,0,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0,0,0,0,0,0,0,0,0,4,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,0,
+5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,0,
+0x17,0x17,0x1c,0x1d,0x1c,0x1d,0x17,0x17,0x17,0x1c,0x1d,0x17,0x1c,0x1d,0x17,0x17,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x13,0,0,0,0,0x1c,0x1d,0,0,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0,0,0,0,0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0,0,0,0,0xc,0x17,0x17,0x17,0x1b,4,5,0x6a,0x14,0x15,0x14,0x15,
+0x14,0x15,0x14,0x15,0x14,0x15,0x1b,0x1b,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,
+0x13,0x14,0x15,0x15,0x1b,0x16a,0x26a,0x36a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,6,6,
+6,6,6,6,0x13,4,4,4,4,4,0x1b,0x1b,0xa6a,0x146a,0x1e6a,4,
+5,0x17,0x1b,0x1b,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,0,6,6,0x1a,
+0x1a,4,4,5,0x13,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0x17,4,4,4,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0,0,0,0,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,
+0x1b,0x1b,0x16b,0x26b,0x36b,0x46b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0x16b,0x26b,0x36b,0x46b,0x56b,0x66b,0x76b,0x86b,
+0x96b,0xa6b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,
+0,0,0,0,0x1b,0x156b,0x166b,0x176b,0x186b,0x196b,0x1a6b,0x1b6b,0x1c6b,0x1d6b,0x1e6b,0x1f6b,
+0x206b,0x216b,0x226b,0x236b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x246b,0x256b,0x266b,0x276b,0x286b,0x296b,0x2a6b,0x2b6b,0x2c6b,0x2d6b,0x2e6b,
+0x2f6b,0x306b,0x316b,0x326b,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,4,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1a,0x1a,0x1a,0x1a,
+0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,
+0x1a,0x1a,0x1a,4,4,4,4,0,0,0,0,0,0x1a,0x1a,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,8,5,
+5,5,6,5,5,5,5,6,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,8,
+8,6,6,8,0x1b,0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x17,0x17,0x17,0x17,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,
+0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,2,2,2,2,2,2,2,0,0,0,0,0,
+0,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,
+0,5,6,5,5,5,5,5,5,5,5,5,5,0x18,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,5,5,5,5,
+5,0,5,0,5,5,0,5,5,0,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0x14,0x15,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,0,0,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,5,5,5,5,5,5,0x19,0x1b,0,0,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14,0x15,0x17,0,0,0,0,0,0,
+6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,
+0x17,0x13,0x13,0x16,0x16,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,0x15,0x14,
+0x15,0x17,0x17,0x14,0x15,0x17,0x17,0x17,0x17,0x16,0x16,0x16,0x17,0x17,0x17,0,
+0x17,0x17,0x17,0x17,0x13,0x14,0x15,0x14,0x15,0x14,0x15,0x17,0x17,0x17,0x18,0x13,
+0x18,0x18,0x18,0,0x17,0x19,0x17,0x17,0,0,0,0,5,5,5,5,
+5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0,0,0x10,0,0x17,0x17,0x17,0x19,0x17,0x17,0x17,0x14,0x15,0x17,0x18,
+0x17,0x13,0x17,0x17,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x17,0x17,
+0x18,0x18,0x18,0x17,0x1a,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0x14,
+0x18,0x15,0x18,0x14,0x15,0x17,0x14,0x15,0x17,0x17,5,5,5,5,5,5,
+5,5,5,5,4,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,4,4,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0,0,0,5,5,5,5,5,5,
+0,0,5,5,5,5,5,5,0,0,5,5,5,5,5,5,
+0,0,5,5,5,0,0,0,0x19,0x19,0x18,0x1a,0x1b,0x19,0x19,0,
+0x1b,0x18,0x18,0x18,0x18,0x1b,0x1b,0,0,0,0,0,0,0,0,0,
+0,0x10,0x10,0x10,0x1b,0x1b,0,0,5,5,5,5,5,5,5,5,
+5,5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,
+5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0,0,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,
+0,0,0,0,0x17,0x17,0x1b,0,0,0,0,0x16b,0x26b,0x36b,0x46b,0x56b,
+0x66b,0x76b,0x86b,0x96b,0xa6b,0x146b,0x1e6b,0x286b,0x326b,0x3c6b,0x466b,0x506b,0x5a6b,0x646b,0xc86b,0x30ab,
+0x40ab,0x50ab,0x60ab,0x70ab,0x80ab,0x90ab,0x11ab,0x21ab,0x31ab,0x41ab,0x51ab,0x61ab,0x71ab,0x81ab,0x91ab,0x12ab,
+0x22ab,0x32ab,0x42ab,0x52ab,0x62ab,0x72ab,0x82ab,0x92ab,0,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0xa8a,0x88a,0x16a,0x56a,0x326a,0x50aa,0x51aa,0x52aa,0x56a,0xa6a,0x326a,0x646a,
+0x50aa,0x11aa,0x51aa,0x56a,0xa6a,0x326a,0x646a,0x50aa,0x11aa,0x12aa,0x52aa,0xa6a,0x16a,0x16a,0x16a,0x26a,
+0x26a,0x26a,0x26a,0x56a,0xa6a,0xa6a,0xa6a,0xa6a,0xa6a,0x1e6a,0x326a,0x326a,0x326a,0x326a,0x646a,0x30aa,
+0x50aa,0x50aa,0x50aa,0x50aa,0x50aa,0x11aa,0x51aa,0x56a,0x326a,0x88b,0x88b,0x118b,0x1a8b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x6b,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x16b,0x56b,0xa6b,0x326b,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x5a6a,5,5,5,5,5,5,5,5,0x90aa,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,0x17,
+5,5,5,5,0,0,0,0,5,5,5,5,5,5,5,5,
+0x17,0x16a,0x26a,0xa6a,0x146a,0x646a,0,0,0,0,0,0,0,0,0,0,
+1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+5,5,5,5,5,5,0,0,5,0,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0,5,5,0,0,0,5,0,0,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0x16b,0xa6b,0x146b,0x646b,0,0,0,0,0,0x17,5,6,6,6,
+0,6,6,0,0,0,0,0,6,6,6,6,5,5,5,5,
+0,5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,
+6,6,6,0,0,0,0,6,0x14b,0x24b,0x34b,0x44b,0xa6b,0x146b,0x646b,0x11ab,
+0,0,0,0,0,0,0,0,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
+0x17,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x26a,0x36a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,
+0x36a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,0x16a,0x26a,0x36a,
+0x46a,0x56a,0x66a,0x76a,0x86a,0x96a,0x16a,0x26a,0x36a,0x46a,0x56a,0x26a,0x36a,0x36a,0x46a,0x56a,
+0x66a,0x76a,0x86a,0x96a,0x16a,0x26a,0x36a,0x36a,0x46a,0x56a,0xa,0xa,0x16a,0x26a,0x36a,0x36a,
+0x46a,0x56a,0x36a,0x36a,0x46a,0x46a,0x46a,0x46a,0x66a,0x76a,0x76a,0x76a,0x86a,0x86a,0x96a,0x96a,
+0x96a,0x96a,0x26a,0x36a,0x46a,0x56a,0x66a,0x16a,0x26a,0x36a,0x46a,0x46a,0x56a,0x56a,0xa,0xa,
+0x16a,0x26a,0x98a,0x118a,0x2c8a,0x98a,0x118a,0xe8a,0xa8a,0xc8a,0xa8a,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x17,0x17,0x17,0x17,0,0,0,0,
+0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,
+0,0,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,8,8,6,6,6,0x1b,0x1b,
+0x1b,8,8,8,8,8,8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,6,
+6,6,6,6,6,6,6,0x1b,0x1b,6,6,6,6,6,6,6,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,6,6,6,6,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0,0,0x1b,0x1b,6,6,
+6,0x1b,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,
+0x1b,0x1b,0x1b,0,0,0,0,0,0,0,0,0,0x16b,0x26b,0x36b,0x46b,
+0x56b,0x66b,0x76b,0x86b,0x96b,0xa6b,0x146b,0x1e6b,0x286b,0x326b,0x3c6b,0x466b,0x506b,0x5a6b,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,
+2,0,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+1,0,1,1,0,0,1,0,0,1,1,0,0,1,1,1,
+1,0,1,1,1,1,1,1,1,1,2,2,2,2,0,2,
+0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,
+2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,2,2,2,2,1,1,0,1,1,1,1,0,
+0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
+1,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,1,1,0,1,
+1,1,1,0,1,1,1,1,1,0,1,0,0,0,1,1,
+1,1,1,1,1,0,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,2,2,2,2,2,2,0,0,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,0x18,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0x18,
+2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0x18,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+2,2,2,2,2,0x18,2,2,2,2,2,2,1,1,1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,0x18,
+2,2,2,2,2,2,1,2,0,0,0x29,0x129,0x229,0x329,0x429,0x529,
+0x629,0x729,0x829,0x929,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x29,0x129,
+0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,
+0x829,0x929,0x29,0x129,0x229,0x329,0x429,0x529,0x629,0x729,0x829,0x929,0,0x10,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x10,0x10,0x10,0x10,
+0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
+0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,6,6,6,6,
+6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0,0,0,0,0,0,0,0,0,0,5,5,5,5,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x11,0x11,0x11,0x11,
+0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
+0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0,0,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0x65,5,5,5,5,5,5,5,5,5,
+0x165,5,5,0x765,5,5,5,0x12a5,5,0x365,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x165,5,5,5,5,5,5,5,0x165,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0x165,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x165,0x265,0x365,5,0x265,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0x165,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,0x265,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x265,5,5,5,5,5,5,5,0x565,5,0x465,5,5,5,5,5,
+5,5,5,5,5,0x265,5,0x865,5,0x665,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0x265,5,
+5,5,5,0x265,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x265,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x365,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,0x365,0x365,0x365,
+0x365,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,0x665,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x365,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,0x365,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,0x365,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0x365,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,0x465,5,5,5,5,5,5,0x465,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x465,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0x465,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x465,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,0x565,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0x565,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,0x565,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0x665,5,5,5,5,5,
+0x6465,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,0x665,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,0x765,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0x765,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x765,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x865,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,0x965,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0x965,0x1465,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0x965,5,5,5,5,5,
+5,5,5,5,0xa65,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,0x11a5,5,0xa65,5,0x11a5,0x1465,0x1e65,5,5,5,5,5,5,
+0x2865,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,0xa65,5,5,5,5,0x1e65,5,5,5,5,5,5,5,5,
+0x2865,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+0x2865,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x6465,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,0x6465,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x12a5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,0x16a5,5,5,5,5,0x16a5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,0x1aa5,5,5,5,5,5,
+5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+5,5,5,5,0x820,0x840,0x860,0,0,0,0,0,0x880,0x8a0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0x8c0,0x8e0,0,0,0,0,0,0,0,0,0,0,
+0x900,0x920,0x940,0x920,0x920,0x920,0x920,0x920,0x960,0x920,0x980,0x920,0x920,0x920,0x9a0,0x920,
+0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x9c0,0x920,0x920,0x920,0x920,0x920,0x920,0x920,
+0x920,0x920,0x920,0x920,0x920,0x9e0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0xa00,0,0xa20,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0xa40,0xa40,0xa40,0xa40,
+0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,
+0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa60
+};
+
+static const UTrie propsTrie={
+ propsTrie_index,
+ NULL,
+ utrie_defaultGetFoldingOffset,
+ 2688,
+ 10752,
+ 0,
+ TRUE
+};
+
+static const uint16_t propsVectorsTrie_index[16924]={
+0x2a8,0x2b0,0x2b8,0x2c0,0x2c8,0x2d0,0x2d8,0x2e0,0xb1b,0xb22,0xb2a,0xb31,0xb39,0xb41,0xb49,0xb51,
+0xb58,0xde3,0xb60,0xb64,0xb67,0xb6d,0xa52,0xb75,0xcdc,0xcdc,0xce4,0x340,0x348,0x350,0x358,0xb7d,
+0xba9,0xca7,0xb85,0xb8d,0x360,0xb93,0xb9b,0xba1,0x860,0x368,0x36d,0x375,0x37c,0xcbc,0x384,0x38a,
+0x392,0x39a,0x3a2,0xbb9,0xbc9,0xbcb,0xbb1,0xbc1,0x3aa,0xdeb,0x3b2,0x91a,0xdf3,0x3ba,0x1016,0x9cc,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x3c2,0x3c8,0x3d0,0x3d8,0x3e0,0x3e6,0x3ee,0x3f6,
+0x3fe,0x404,0x40c,0x414,0x41c,0x422,0x42a,0x432,0x43a,0x440,0x448,0x450,0x458,0x460,0x468,0x46f,
+0x477,0x47d,0x485,0x48d,0x495,0x49b,0x4a3,0x4ab,0x4b3,0x4b9,0x4c1,0x4c9,0x4d1,0x4d8,0x4e0,0x4e8,
+0x4f0,0x4f4,0x4fc,0x503,0x50b,0x513,0x51b,0x523,0xdad,0xdb5,0x52b,0x533,0x53b,0x543,0x54b,0x550,
+0xe70,0x558,0x560,0x567,0x567,0xbd3,0x56f,0x573,0xd74,0xd74,0x57b,0xd84,0xd85,0x583,0xd7c,0x585,
+0xdfb,0xdfd,0x58d,0xdfd,0x595,0x59a,0x5a2,0xe02,0x5a8,0xdfd,0x5ae,0x5b6,0x959,0xe0a,0xe0a,0x5be,
+0x5c6,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,0xe12,
+0xe12,0xe12,0xe12,0x5cb,0x5d3,0xe1a,0xe1a,0x5db,0x868,0x870,0x878,0x880,0xe80,0xe78,0x5e3,0x5eb,
+0x5f3,0xe22,0xe2a,0x5fb,0xe22,0x2e8,0x2a0,0x2a0,0x897,0x89f,0x8a7,0x8ac,0x100e,0x994,0x99c,0xf5e,
+0x922,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x101e,0x1023,0x9d4,0x9dc,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0xf7e,0xf66,0xf76,0xf6e,0xfee,0xfe6,0x936,0x939,
+0xbdb,0xbdb,0xbdb,0xbdb,0x603,0xbdb,0xbdb,0x60b,0x613,0xbe3,0x617,0x61f,0xbe3,0x627,0x62f,0x637,
+0xa62,0xa5a,0xbeb,0x63f,0x647,0x64f,0x655,0x65d,0xa6a,0xa72,0x665,0xa7a,0x66d,0xbf3,0xa82,0xbfa,
+0xa8a,0xa92,0xa9a,0xaa2,0xaaa,0xab1,0xc02,0xc0a,0xab9,0xc12,0xc15,0xc17,0xe32,0xf13,0xf19,0x675,
+0xc1f,0x67d,0x685,0xac1,0xac6,0xac9,0xacf,0xa42,0xad7,0xad7,0xadc,0xa4a,0xae4,0xaec,0xaf4,0xafc,
+0xb04,0xc27,0xb0b,0xb13,0x68d,0x695,0x69a,0x69a,0x6a2,0x6a8,0x6b0,0x6b8,0x6c0,0x6c6,0x888,0x88f,
+0xe3a,0xe3a,0xe3a,0xe3a,0xe3a,0xe3a,0xe3a,0xe3a,0xf21,0xf21,0xf21,0xf21,0xf29,0xf30,0xf32,0xf39,
+0xf41,0xf45,0xf45,0xf48,0xf45,0xf45,0xf4e,0xf45,0x8b4,0x8bc,0x8bd,0x8bd,0x8bd,0x8bd,0x8bd,0x8bd,
+0xfd6,0x969,0x96d,0x9e4,0xfc6,0xfc6,0xfc6,0x941,0xfce,0x961,0xffe,0x9bc,0x949,0x951,0x951,0x2a0,
+0x9ac,0x9b4,0x9b4,0x9b4,0x6ce,0xe42,0xe42,0x6d6,0xe4a,0xe4a,0xe4a,0xe4a,0xe4a,0xe4a,0x6de,0x2ec,
+0xcd4,0xcec,0x6e6,0xcf4,0x6ee,0xcfc,0xd04,0xd0c,0x6f6,0x6fb,0xd14,0xd1b,0x700,0x708,0x92a,0x92e,
+0x710,0xd2b,0x718,0xd23,0xd34,0xd38,0xd30,0x720,0xd56,0xd56,0xd40,0xd46,0xd56,0xd56,0xd57,0xd4e,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,
+0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0xe52,0x728,0xf86,0xf86,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,
+0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0xd5f,0x730,0x737,0x737,
+0xe5a,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,
+0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,0xe60,
+0xe60,0xe60,0xe60,0xe60,0x73f,0xe68,0x2f4,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x98c,0x9ec,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,
+0xff6,0x2fc,0x102b,0x9f5,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,
+0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,
+0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,
+0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,
+0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,
+0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,
+0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,
+0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,
+0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,
+0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,
+0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,
+0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,
+0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,
+0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,
+0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,
+0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,
+0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,
+0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,
+0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,
+0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,
+0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,
+0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0xddb,0xdd5,0xdd6,0xdd7,0xdd8,0xdd9,0xdda,0x304,0x2a0,0x2a0,
+0x1043,0x1046,0x104e,0x1054,0x105c,0x105d,0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,
+0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,0x2a0,0x1065,0x106d,0x1065,0x1075,0x1076,0x107e,0x107f,
+0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,
+0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,0xdcd,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,
+0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xa3a,0xd67,0xd67,0xd67,0xd67,0xd67,0xd67,0xd67,0xd67,
+0xd6c,0x747,0xf56,0x74d,0x1006,0x1006,0x751,0x758,0x760,0x768,0x770,0xc3f,0xc46,0x778,0x77d,0xc4e,
+0xc84,0xc84,0xc2f,0xc37,0xc56,0xc7b,0xc7c,0xc8c,0xc5e,0xc63,0x785,0xc6b,0x78d,0xc73,0x795,0x799,
+0x9c4,0x7a1,0x7a9,0x7b1,0xc94,0xc9a,0xc9f,0x7b9,0x7c9,0xcc4,0xccc,0xcaf,0xcb4,0x7d1,0x7d9,0x7c1,
+0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,
+0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdbd,0xdc5,0xdc5,0xdc5,0xdc5,
+0x8c5,0x8cc,0x8d4,0x8dc,0xf8e,0xf8e,0xf8e,0x8e4,0x8ec,0x8ef,0xfbe,0xfb6,0x30c,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x7e1,0x7e9,0x314,0x2a0,0x8f7,0xfde,0x9a4,0x2a0,
+0xe95,0xe88,0xe8d,0xf96,0x8ff,0x31c,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x907,0x90a,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x9fd,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x975,0x97c,0x984,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,
+0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0x1033,0xa05,0xa09,0xa09,0xa09,0xa09,
+0x103b,0x103b,0x103b,0xa11,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0xe9d,0xe9d,0xe9d,0xe9d,0xe9d,0xe9d,0xe9d,0x7f1,0xea5,0x7f9,0xea6,0xeae,0xeb6,0xebc,0x801,0x809,
+0xfae,0xfae,0x324,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0xf9e,0xf9e,0x912,0xa19,0x2a0,0x2a0,0x2a0,0x2a0,
+0xee5,0xee0,0x811,0xee3,0x819,0x821,0x829,0xee9,0x831,0x839,0x841,0xee2,0xeea,0xee5,0xee0,0xee8,
+0xee3,0xeeb,0xee6,0xee1,0xee9,0x848,0xec4,0xecc,0xed3,0xeda,0xec7,0xecf,0xed6,0xedd,0x850,0xf0b,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,
+0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x2a0,0x328,
+0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,
+0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,
+0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,
+0xefb,0xefb,0xefb,0xefb,0xefb,0xefb,0xa2a,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,
+0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,
+0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,
+0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,0xf03,
+0xa32,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,
+0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,
+0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa21,0xa22,
+0x858,0xef3,0xef3,0xef3,0x330,0x330,0x330,0x330,0xfa6,0xfa6,0xfa6,0xfa6,0xfa6,0xfa6,0xfa6,0x338,
+0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,
+0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,
+0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,0x330,
+0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,
+0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,
+0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,
+0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd9d,0xd8d,
+0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,
+0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,
+0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,
+0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xda5,0xd95,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x426,0x621,0x450,0x450,0x54c,0x495,0x495,
+0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,0x495,
+0x747,0x561,0x717,0x3ff,0x6fc,0x6d2,0x3ff,0x71a,0x69f,0x474,0x3ff,0x6ff,0x61b,0x573,0x61e,0x74a,
+0x687,0x687,0x687,0x687,0x687,0x687,0x687,0x687,0x687,0x687,0x618,0x61b,0x402,0x402,0x402,0x561,
+0x3ff,0x417,0x417,0x417,0x417,0x417,0x417,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,
+0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x411,0x69f,0x6fc,0x474,0x408,0x40b,
+0x405,0x414,0x414,0x414,0x414,0x414,0x414,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,
+0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x40e,0x69f,0x447,0x474,0x402,0x495,
+0x498,0x498,0x498,0x498,0x498,0x750,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,
+0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,0x498,
+0x567,0x17d,0x6d5,0x702,0x6ed,0x702,0x41a,0x17d,0x183,0x1f2,0x189,0x708,0x41d,0x43b,0x3a8,0x420,
+0x6c0,0x6f0,0x17a,0x17a,0x44d,0x1f5,0x17d,0x186,0x183,0x17a,0x189,0x708,0x177,0x177,0x177,0x17d,
+0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x3b1,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,
+0x3b1,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x180,0x3b1,0x1fb,0x1fb,0x1fb,0x1fb,0x1fb,0x3b1,0x3ab,
+0x3ae,0x3ae,0x1f8,0x1f8,0x1f8,0x1f8,0x3ab,0x1f8,0x3ae,0x3ae,0x3ae,0x1f8,0x3ae,0x3ae,0x1f8,0x1f8,
+0x3ab,0x1f8,0x3ae,0x3ae,0x1f8,0x1f8,0x1f8,0x180,0x3ab,0x3ae,0x3ae,0x1f8,0x3ae,0x1f8,0x3ab,0x1f8,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x8b8,0x5d,0x5d,0x5d,0x5d,0x5d,0x5d,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x8d9,0x8d9,0x8dc,0x8dc,0x8d9,0x8d9,0x8d9,0x8d9,0x8d9,0x8d9,0x8d9,0x8d9,0x8d,0x8d,0x8d,0x8d,
+0x8ee,0xa41,0x8ee,0x8ee,0x8ee,0xa41,0x8ee,0xa8,0xa8,0xa8,0xa8,0xa8,0xa8,0xa8,0xa8,0xa8,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xbf1,0xbf1,0xbf1,0xc4b,0xc4b,0xc42,0xc42,0xc4b,0xbee,0xbee,0xbee,0xbee,0x138,0x138,0x138,0x138,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x7c5,0x7c5,0x7c5,0x7c5,0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0x10b,0x10b,0x10b,0x10b,0x10b,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0xc9,0xc9,0xc9,0xc9,0xc9,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xb4f,0xff,0xff,0xff,0xff,0xff,0xff,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0xba9,0xba9,0xc2a,0xc2a,0xc2a,0xba9,0x108,0x108,0x108,0x108,0x108,0x108,0x108,0x108,0x108,0x108,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x765,0x765,
+3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,
+3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+0x570,0x570,0x8cd,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,0xa2c,
+6,6,6,6,0x243,0x240,6,6,6,6,0x249,0xc93,0xc93,0xc93,0x60f,6,
+6,6,6,6,0x246,0x243,0x258,0x237,0x258,0x258,0x258,6,0x258,6,0x258,0x258,
+0x24f,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,
+0x3cf,0x3cf,6,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x3cf,0x258,0x258,0x24f,0x24f,0x24f,0x24f,
+0x24f,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,
+0x3cc,0x3cc,0x24c,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x3cc,0x24f,0x24f,0x24f,0x24f,0x24f,6,
+0x25b,0x25b,0x25e,0x258,0x258,0x25b,0x252,0x7e3,0x98d,0x98a,0x255,0x7e3,0x255,0x7e3,0x255,0x7e3,
+0x26a,0x264,0x261,0x49b,0x49b,0x49b,0x49b,9,0x894,0x894,0x993,0x990,0x7ec,0x7e6,0x7ec,0x7e6,
+0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,
+0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,
+0xc,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,
+0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0x27c,0xc,0xc,0x27f,0x270,0x270,
+0x273,0x270,0x273,0x270,0xc,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,
+0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x276,
+0x276,0x276,0x276,0x276,0x276,0x276,0x276,0x279,0xc,0x612,0x86a,0xc,0xc,0xc,0xc,0xc,
+0xf,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,
+0x282,0x49e,0x49e,0x28b,0x78f,0xc1e,0xc51,0xc1e,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,
+0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,0x28e,
+0x28e,0x28e,0x28e,0xf,0xf,0xf,0xf,0xf,0x28e,0x28e,0x28e,0x288,0x285,0xf,0xf,0xf,
+0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xa89,0xa89,0xa89,0xa89,0x12,0x12,0x12,0x12,
+0x12,0x12,0x12,0xc7b,0x54f,0xb49,0xa8c,0xa8c,0xb13,0xb13,0xb13,0xb13,0xb13,0xb13,0x12,0x12,
+0x12,0x12,0x12,0x54f,0x12,0x12,0xc54,0x552,0x12,0x29a,0x29d,0x29d,0x29d,0x29d,0x29d,0x29a,
+0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x12,0x12,0x12,0x12,0x12,0x294,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x4a4,0x4a4,0x4a4,0x4a4,0x4a4,0x4a4,0x4a4,0x4a4,0x897,0x897,0x897,0xb13,0xb19,
+0xb16,0xc21,0xc21,0xc21,0xc21,0xc21,0xc21,0x12,0x801,0x801,0x801,0x7fe,0x7fe,0x7fe,0x7fe,0x7fe,
+0x7fe,0x7fe,0x7fe,0x7fb,0x7fe,0x7fb,0x15,0x7f8,0x804,0x89a,0x804,0x804,0x804,0x804,0x804,0x804,
+0x804,0x804,0x804,0x804,0x804,0x804,0x804,0x804,0x89d,0x89d,0x89d,0x89d,0x89d,0x89d,0x89d,0x89d,
+0x89d,0x89d,0x89d,0x15,0x15,0xa92,0xa92,0xa92,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,
+0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0x807,0x807,0x807,0x807,0x807,0x807,0x8a3,0x8a3,
+0x8a3,0x8a3,0x8a3,0x8a3,0x8a3,0x8a3,0x8a3,0x8a3,0x8a3,0x999,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1b,0x4b0,0x4b0,0x4b9,0xa95,0x2a9,0x2a9,0x2a9,
+0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,
+0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2ac,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,
+0x2a9,0x2ac,0x2a9,0x2a9,0x2ac,0x2a9,0x2a9,0x2a9,0x2a9,0x2a9,0x1b,0x1b,0x4b3,0x2a9,0x4b9,0x4b9,
+0x4b9,0x4b0,0x4b0,0x4b0,0x4b0,0x4b0,0x4b0,0x4b0,0x4b0,0x4b9,0x4b9,0x4b9,0x4b9,0x4b6,0x1b,0x1b,
+0x2a9,0x4b3,0x4b3,0x4b3,0x4b3,0x1b,0x1b,0x1b,0x2ac,0x2ac,0x2ac,0x2ac,0x2ac,0x2ac,0x2ac,0x2ac,
+0x2a9,0x2a9,0x4b0,0x4b0,0x42c,0x42c,0x666,0x666,0x666,0x666,0x666,0x666,0x666,0x666,0x666,0x666,
+0x2a6,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0x1b,0xc9c,0xc9c,0xb73,0xc9c,0xc9c,
+0x1e,0x4bc,0x4c5,0x4c5,0x1e,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x1e,0x1e,0x2b2,
+0x2b2,0x1e,0x1e,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,
+0x2b2,0x1e,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x2b2,0x1e,0x2b2,0x1e,0x1e,0x1e,0x2b2,0x2b2,
+0x2b2,0x2b2,0x1e,0x1e,0x4bf,0xa98,0x4bc,0x4c5,0x4c5,0x4bc,0x4bc,0x4bc,0x4bc,0x1e,0x1e,0x4c5,
+0x4c5,0x1e,0x1e,0x4c8,0x4c8,0x4c2,0xb76,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x4bc,
+0x1e,0x1e,0x1e,0x1e,0x2b5,0x2b5,0x1e,0x2b5,0x2b2,0x2b2,0x4bc,0x4bc,0x1e,0x1e,0x669,0x669,
+0x669,0x669,0x669,0x669,0x669,0x669,0x669,0x669,0x2b2,0x2b2,0x6db,0x6db,0x2af,0x2af,0x2af,0x2af,
+0x2af,0x2af,0x2af,0x1e,0x1e,0x1e,0x1e,0x1e,0x21,0xb1c,0x4cb,0xb1f,0x21,0x2b8,0x2b8,0x2b8,
+0x2b8,0x2b8,0x2b8,0x21,0x21,0x21,0x21,0x2b8,0x2b8,0x21,0x21,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,
+0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x21,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,0x2b8,
+0x2b8,0x21,0x2b8,0x2bb,0x21,0x2b8,0x2bb,0x21,0x2b8,0x2b8,0x21,0x21,0x4ce,0x21,0x4d4,0x4d4,
+0x4d4,0x4cb,0x4cb,0x21,0x21,0x21,0x21,0x4cb,0x4cb,0x21,0x21,0x4cb,0x4cb,0x4d1,0x21,0x21,
+0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x2bb,0x2bb,0x2bb,0x2b8,0x21,0x2bb,0x21,
+0x21,0x21,0x21,0x21,0x21,0x21,0x66c,0x66c,0x66c,0x66c,0x66c,0x66c,0x66c,0x66c,0x66c,0x66c,
+0x4cb,0x4cb,0x2b8,0x2b8,0x2b8,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,
+0x24,0x4d7,0x4d7,0x4e0,0x24,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0xa9b,0x2be,0x24,0x2be,
+0x2be,0x2be,0x24,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,
+0x2be,0x24,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x2be,0x24,0x2be,0x2be,0x24,0x2be,0x2be,0x2be,
+0x2be,0x2be,0x24,0x24,0x4da,0x2be,0x4e0,0x4e0,0x4e0,0x4d7,0x4d7,0x4d7,0x4d7,0x4d7,0x24,0x4d7,
+0x4d7,0x4e0,0x24,0x4e0,0x4e0,0x4dd,0x24,0x24,0x2be,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
+0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x2be,0xa9b,0xb22,0xb22,0x24,0x24,0x66f,0x66f,
+0x66f,0x66f,0x66f,0x66f,0x66f,0x66f,0x66f,0x66f,0x24,0xb55,0x24,0x24,0x24,0x24,0x24,0x24,
+0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x27,0x4e3,0x4ec,0x4ec,0x27,0x2c4,0x2c4,0x2c4,
+0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x27,0x27,0x2c4,0x2c4,0x27,0x27,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,
+0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x27,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,0x2c4,
+0x2c4,0x27,0x2c4,0x2c4,0x27,0xa9e,0x2c4,0x2c4,0x2c4,0x2c4,0x27,0x27,0x4e6,0x2c4,0x4e3,0x4e3,
+0x4ec,0x4e3,0x4e3,0x4e3,0x27,0x27,0x27,0x4ec,0x4ef,0x27,0x27,0x4ef,0x4ef,0x4e9,0x27,0x27,
+0x27,0x27,0x27,0x27,0x27,0x27,0x4e3,0x4e3,0x27,0x27,0x27,0x27,0x2c7,0x2c7,0x27,0x2c4,
+0x2c4,0x2c4,0x27,0x27,0x27,0x27,0x672,0x672,0x672,0x672,0x672,0x672,0x672,0x672,0x672,0x672,
+0x2c1,0xa9e,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,
+0x2a,0x2a,0x4f2,0x2cd,0x2a,0x2cd,0x2cd,0x2cd,0x2cd,0x2cd,0x2cd,0x2a,0x2a,0x2a,0x2cd,0x2cd,
+0x2cd,0x2a,0x2cd,0x2cd,0x2d0,0x2cd,0x2a,0x2a,0x2a,0x2cd,0x2cd,0x2a,0x2cd,0x2a,0x2cd,0x2cd,
+0x2a,0x2a,0x2a,0x2cd,0x2cd,0x2a,0x2a,0x2a,0x2cd,0x2cd,0x2cd,0x2a,0x2a,0x2a,0x2cd,0x2cd,
+0x2cd,0x2cd,0x2cd,0x2cd,0x2cd,0x2cd,0xb79,0x2cd,0x2cd,0x2cd,0x2a,0x2a,0x2a,0x2a,0x4f2,0x4f8,
+0x4f2,0x4f8,0x4f8,0x2a,0x2a,0x2a,0x4f8,0x4f8,0x4f8,0x2a,0x4fb,0x4fb,0x4fb,0x4f5,0x2a,0x2a,
+0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x4f2,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,
+0x2a,0x2a,0xc6f,0x675,0x675,0x675,0x675,0x675,0x675,0x675,0x675,0x675,0x2ca,0x2ca,0x2ca,0xaa1,
+0xaa1,0xaa1,0xaa1,0xaa1,0xaa1,0xb58,0xaa1,0x2a,0x2a,0x2a,0x2a,0x2a,0x2d,0x507,0x507,0x507,
+0x2d,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d,0x2d3,0x2d3,0x2d3,0x2d,0x2d3,0x2d3,
+0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d,0x2d3,0x2d3,
+0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d,0x2d3,0x2d3,0x2d3,0x2d3,0x2d3,0x2d,0x2d,
+0x2d,0x2d,0x4fe,0x4fe,0x4fe,0x507,0x507,0x507,0x507,0x2d,0x4fe,0x4fe,0x501,0x2d,0x4fe,0x4fe,
+0x4fe,0x504,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x4fe,0x4fe,0x2d,0x2d,0x2d,0x2d,0x2d,
+0x2d,0x2d,0x2d,0x2d,0x2d3,0x2d3,0x2d,0x2d,0x2d,0x2d,0x678,0x678,0x678,0x678,0x678,0x678,
+0x678,0x678,0x678,0x678,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
+0x2d,0x2d,0x2d,0x2d,0x30,0x30,0x510,0x510,0x30,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,
+0x2d6,0x30,0x2d6,0x2d6,0x2d6,0x30,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,
+0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x30,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,
+0x30,0x2d6,0x2d6,0x2d6,0x2d6,0x2d6,0x30,0x30,0xb25,0xaa4,0x510,0x50a,0x513,0x510,0x50a,0x510,
+0x510,0x30,0x50a,0x513,0x513,0x30,0x513,0x513,0x50a,0x50d,0x30,0x30,0x30,0x30,0x30,0x30,
+0x30,0x50a,0x50a,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x2d6,0x30,0x2d6,0x2d6,0xd0e,0xd0e,
+0x30,0x30,0x67b,0x67b,0x67b,0x67b,0x67b,0x67b,0x67b,0x67b,0x67b,0x67b,0x30,0xc9f,0xc9f,0x30,
+0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x33,0x33,0x51c,0x51c,
+0x33,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x33,0x2d9,0x2d9,0x2d9,0x33,0x2d9,0x2d9,
+0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x33,0x2d9,0x2d9,
+0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x2d9,0x33,0x33,
+0x33,0x33,0x516,0x51c,0x51c,0x516,0x516,0x516,0x33,0x33,0x51c,0x51c,0x51c,0x33,0x51f,0x51f,
+0x51f,0x519,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x516,0x33,0x33,0x33,0x33,
+0x33,0x33,0x33,0x33,0x2d9,0x2d9,0x33,0x33,0x33,0x33,0x67e,0x67e,0x67e,0x67e,0x67e,0x67e,
+0x67e,0x67e,0x67e,0x67e,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
+0x33,0x33,0x33,0x33,0x36,0x36,0x8ac,0x8ac,0x36,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,
+0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x36,0x36,0x36,0x80d,0x80d,
+0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,
+0x80d,0x80d,0x36,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x36,0x80d,0x36,0x36,
+0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x80d,0x36,0x36,0x36,0x8a9,0x36,0x36,0x36,0x36,0x8a6,
+0x8ac,0x8ac,0x8a6,0x8a6,0x8a6,0x36,0x8a6,0x36,0x8ac,0x8ac,0x8af,0x8ac,0x8af,0x8af,0x8af,0x8a6,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x8ac,0x8ac,0x80a,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x39,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,
+0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,0x729,
+0x729,0x71d,0x729,0x726,0x71d,0x71d,0x71d,0x71d,0x71d,0x71d,0x723,0x39,0x39,0x39,0x39,0x6de,
+0x72f,0x72f,0x72f,0x72f,0x72f,0x729,0x72c,0x720,0x720,0x720,0x720,0x720,0x720,0x71d,0x720,0x2dc,
+0x681,0x681,0x681,0x681,0x681,0x681,0x681,0x681,0x681,0x681,0x42f,0x42f,0x39,0x39,0x39,0x39,
+0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,
+0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x3c,0x73b,0x73b,0x3c,
+0x73b,0x3c,0x3c,0x73b,0x73b,0x3c,0x73b,0x3c,0x3c,0x73b,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,
+0x73b,0x73b,0x73b,0x73b,0x3c,0x73b,0x73b,0x73b,0x73b,0x73b,0x73b,0x73b,0x3c,0x73b,0x73b,0x73b,
+0x3c,0x73b,0x3c,0x73b,0x3c,0x3c,0x73b,0x73b,0x3c,0x73b,0x73b,0x73b,0x73b,0x732,0x73b,0x738,
+0x732,0x732,0x732,0x732,0x732,0x732,0x3c,0x732,0x732,0x73b,0x3c,0x3c,0x744,0x744,0x744,0x744,
+0x744,0x3c,0x741,0x3c,0x735,0x735,0x735,0x735,0x735,0x732,0x3c,0x3c,0x684,0x684,0x684,0x684,
+0x684,0x684,0x684,0x684,0x684,0x684,0x3c,0x3c,0x73e,0x73e,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,
+0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,
+0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x777,0x777,0x777,0x77a,
+0x777,0x777,0x777,0x777,0x3f,0x777,0x777,0x777,0x777,0x77a,0x777,0x777,0x777,0x777,0x77a,0x777,
+0x777,0x777,0x777,0x77a,0x777,0x777,0x777,0x777,0x77a,0x777,0x777,0x777,0x777,0x777,0x777,0x777,
+0x777,0x777,0x777,0x777,0x777,0x77a,0x813,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x792,0x792,0x795,
+0x792,0x795,0x795,0x798,0x795,0x798,0x792,0x792,0x792,0x792,0x792,0x783,0x792,0x795,0x79b,0x79b,
+0x79e,0x780,0x79b,0x79b,0x777,0x777,0x777,0x777,0x3f,0x3f,0x3f,0x3f,0x792,0x792,0x792,0x795,
+0x792,0x792,0x8b2,0x792,0x3f,0x792,0x792,0x792,0x792,0x795,0x792,0x792,0x792,0x792,0x795,0x792,
+0x792,0x792,0x792,0x795,0x792,0x792,0x792,0x792,0x795,0x792,0x8b2,0x8b2,0x8b2,0x792,0x792,0x792,
+0x792,0x792,0x792,0x792,0x8b2,0x795,0x8b2,0x8b2,0x8b2,0x3f,0x86d,0x86d,0x810,0x810,0x810,0x810,
+0x810,0x810,0x8b5,0x810,0x810,0x810,0x810,0x810,0x810,0x3f,0x3f,0x810,0xc0f,0xc0f,0x3f,0x3f,
+0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
+0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,
+0x918,0x918,0x42,0x918,0x918,0x918,0x91b,0x918,0x42,0x918,0x918,0x42,0x915,0x90c,0x90c,0x90c,
+0x90c,0x915,0x90c,0x42,0x42,0x42,0x90c,0x90f,0x915,0x912,0x42,0x42,0x42,0x42,0x42,0x42,
+0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x8fa,0x870,0x870,0x816,0x816,0x816,0x816,
+0x918,0x918,0x918,0x918,0x918,0x918,0x915,0x915,0x90c,0x90c,0x42,0x42,0x42,0x42,0x42,0x42,
+0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x2e5,0x2e5,0x2e5,0x2e5,
+0x2e5,0x2e5,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x2e2,0x2e2,0x2e2,0x2e2,
+0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,0x2e2,
+0x2e2,0x2e2,0x2e2,0x99c,0x99c,0xb7c,0xb7c,0x2df,0xb7f,0x45,0x45,0x45,0x756,0x756,0x756,0x756,
+0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,
+0x756,0x756,0x756,0x756,0x756,0x756,0x48,0x48,0x48,0x48,0x48,0x759,0x75f,0x75f,0x75f,0x48,
+0x48,0x48,0x48,0x48,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,
+0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x48,0x48,
+0x48,0x48,0x48,0x48,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,0x825,0x4b,0x825,0x825,
+0x825,0x825,0x4b,0x4b,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x4b,0x825,0x4b,0x825,0x825,
+0x825,0x825,0x4b,0x4b,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,0x825,0x4b,0x825,0x825,
+0x825,0x825,0x4b,0x4b,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,0x825,0x4b,0x825,0x825,0x825,0x825,0x4b,0x4b,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x4b,0x825,0x4b,0x825,0x825,0x825,0x825,0x4b,0x4b,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x4b,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,
+0x825,0x4b,0x825,0x825,0x825,0x825,0x4b,0x4b,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0x4b,0x4b,0x4b,0x4b,0xc24,0xb82,0x873,0x81f,0x81c,0x81c,0x81c,0x81c,0x81f,
+0x81f,0x822,0x822,0x822,0x822,0x822,0x822,0x822,0x822,0x822,0x819,0x819,0x819,0x819,0x819,0x819,
+0x819,0x819,0x819,0x819,0x819,0x4b,0x4b,0x4b,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,
+0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x4e,0x4e,0x4e,
+0x4e,0x4e,0x4e,0x4e,0x4e,0x4e,0x4e,0x4e,0x51,0x831,0x831,0x831,0x831,0x831,0x831,0x831,
+0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,
+0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x82b,0x82e,0x831,0x831,0x831,0x831,0x831,
+0x831,0x831,0x831,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x876,0x834,0x834,0x834,
+0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x834,
+0x834,0x834,0x834,0x834,0x834,0x834,0x834,0x903,0x891,0x54,0x54,0x54,0x837,0x837,0x837,0x837,
+0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x879,0x879,0x879,0x837,0x837,0x837,0x57,0x57,0x57,
+0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x57,0x92d,0x92d,0x92d,0x92d,
+0x92d,0x92d,0x921,0x92d,0x92d,0x924,0x924,0x924,0x924,0x924,0x924,0x924,0x924,0x924,0x927,0x92a,
+0x87f,0x87f,0x8f1,0x930,0x87c,0x83a,0x87f,0x906,0x930,0xb5b,0x5a,0x5a,0x8fd,0x8fd,0x8fd,0x8fd,
+0x8fd,0x8fd,0x8fd,0x8fd,0x8fd,0x8fd,0x5a,0x5a,0x5a,0x5a,0x5a,0x5a,0xaa7,0xaa7,0xaa7,0xaa7,
+0xaa7,0xaa7,0xaa7,0xaa7,0xaa7,0xaa7,0x5a,0x5a,0x5a,0x5a,0x5a,0x5a,0x83d,0x83d,0x882,0x885,
+0x888,0x882,0x88e,0x83d,0x888,0x88b,0x83d,0x8bb,0x8bb,0x8bb,0x8c7,0x5d,0x900,0x900,0x900,0x900,
+0x900,0x900,0x900,0x900,0x900,0x900,0x5d,0x5d,0x5d,0x5d,0x5d,0x5d,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x5d,0x5d,0x5d,0x5d,0x5d,0x5d,0x5d,0x5d,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2e8,0x2e8,0x2e8,0x2e8,0x2eb,0x77d,0x60,0x60,0x60,0x60,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x60,0x60,0x60,0x60,0x60,0x60,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x63,0x63,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x63,0x63,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x63,0x2fa,0x63,0x2fa,0x63,0x2fa,0x63,0x2fa,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x2f7,0x63,0x63,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x63,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f4,0x2f7,0x2f4,0x2f4,0x2f1,0x2f7,0x2f7,
+0x2f7,0x63,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f1,0x2f1,0x2f1,0x2f7,0x2f7,0x2f7,0x2f7,
+0x63,0x63,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x63,0x2f1,0x2f1,0x2f1,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f1,0x2f1,0x2f1,0x63,0x63,0x2f7,0x2f7,
+0x2f7,0x63,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f1,0x2f4,0x63,0xa71,0x99f,0x99f,0x99f,
+0x66,0x66,0x66,0x66,0x66,0x66,0x528,0x528,0x528,0x528,0x528,0x528,0x30c,0x9ab,0x69,0x69,
+0x1a1,0x30c,0x30c,0x30c,0x30c,0x30c,0x312,0x318,0x312,0x693,0x45c,0x1a4,0x309,0x19e,0x19e,0x19e,
+0x19e,0x309,0x309,0x309,0x309,0x309,0x30f,0x315,0x30f,0x690,0x459,0x69,0xb8b,0xb8b,0xb8b,0xb8b,
+0xb8b,0x69,0x69,0x69,0x69,0x69,0x69,0x69,0x69,0x69,0x69,0x69,0x6e1,0x6e1,0x6e1,0x6e1,
+0x6e1,0x6e1,0x6e1,0x6bd,0x6e4,0x6f6,0x6e1,0x7b6,0x7cb,0x909,0x909,0x909,0xa6e,0xa6e,0xc7e,0xc7e,
+0xc7e,0xc7e,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,
+0x6c,0x6c,0x6c,0x6c,0x531,0x531,0x531,0x531,0x531,0x531,0x531,0x531,0x531,0x531,0x531,0x531,
+0x531,0x52e,0x52e,0x52e,0x52e,0x531,0x8be,0x8be,0xa11,0xa17,0xa17,0xa14,0xa14,0xa14,0xa14,0xc27,
+0xd11,0xd11,0xd11,0xd11,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,0x6f,
+0x6f,0x6f,0x6f,0x6f,0x9b4,0x9b1,0x9b1,0x9b1,0x9b1,0x9ba,0x9b7,0x9b7,0x9b7,0x9b7,0x9ae,0x9b1,
+0xb8e,0xca2,0xca5,0x72,0x75,0x75,0x75,0x3e7,0x1b3,0x16b,0x33c,0x33c,0x33c,0x33c,0x33c,0x1b3,
+0x3e7,0x3e7,0x1b3,0x33c,0x342,0x342,0x342,0x84f,0xca8,0x75,0x75,0x75,0x75,0x75,0x75,0x75,
+0x75,0x75,0x75,0x75,0x1bf,0x1bf,0x1bf,0x1bf,0x1bf,0x1bc,0x1bc,0x1bc,0x1bc,0x1bc,0x351,0x351,
+0x348,0x348,0x348,0x348,0xcae,0xcae,0xcab,0xcab,0xcab,0xcab,0xcab,0xcab,0x78,0x78,0x78,0x78,
+0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,
+0x78,0x78,0x78,0x78,0x363,0x363,0x363,0x363,0x363,0x858,0x858,0x7b,0x7b,0x7b,0x7b,0x7b,
+0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,0x7b,
+0x7b,0x7b,0x7b,0x7b,0x366,0x366,0x366,0x366,0x366,0x366,0x366,0x366,0x366,0x366,0x366,0x7e,
+0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,
+0x7e,0x7e,0x7e,0x7e,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0xab9,0xab9,
+0xab9,0xab9,0xab9,0xab9,0xab9,0xab9,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,
+0xb97,0x81,0x81,0x81,0xab9,0xab9,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,
+0xb97,0xb97,0xb97,0xb97,0xb97,0xb97,0xcb1,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
+0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
+0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x84,0x375,0x375,0x375,0x375,0x84,0x375,0x375,
+0x375,0x375,0x84,0x84,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,
+0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x84,0x375,0x375,0x375,0x375,0x375,0x375,0x375,
+0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x3ed,0x375,0x375,
+0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x84,0x375,0x84,0x375,
+0x375,0x375,0x375,0x84,0x84,0x84,0x375,0x84,0x375,0x375,0x375,0x70e,0x70e,0x70e,0x70e,0x84,
+0x84,0x375,0x55b,0x55b,0x375,0x375,0x375,0x375,0xa5c,0xa02,0xa5c,0xa02,0xa5c,0xa02,0xa5c,0xa02,
+0xa5c,0xa02,0xa5c,0xa02,0xa5c,0xa02,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,0x1ec,
+0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,0x174,
+0x174,0x174,0x174,0x174,0x375,0x84,0x84,0x84,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,
+0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x84,0x375,0x375,0x375,0x375,0x375,0x375,0x375,
+0x375,0x375,0x375,0x375,0x375,0x375,0x375,0x84,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,
+0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,
+0x8d0,0x8d0,0x87,0x8d0,0x8d0,0x8d0,0x8d0,0x8d3,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,
+0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d3,0x87,0x87,0x87,0x87,
+0x87,0x87,0x87,0x87,0x87,0x87,0x87,0x87,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,
+0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8a,0x8a,
+0x8a,0x8a,0x8a,0x8a,0x8a,0x8a,0x8a,0x8a,0x90,0x642,0x5b5,0x642,0x5b5,0x642,0x5b5,0x642,
+0x5b5,0x642,0x5b5,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,
+0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b5,0x5b5,0x5b5,0x642,0x5b5,0x642,0x5b5,0x642,
+0x5b5,0x5b5,0x5b5,0x5b5,0x5b5,0x5b5,0x642,0x5b5,0x5b5,0x5b5,0x5b5,0x5b5,0x5b8,0xa53,0xa53,0x90,
+0x90,0x549,0x549,0x63f,0x63f,0x645,0x648,0xa38,0x93,0x93,0x93,0x93,0x93,0x5c1,0x5c1,0x5c1,
+0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,
+0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x5c1,0x93,0x93,0x93,0x96,0x5c4,0x5c4,0x5c4,
+0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x96,
+0x5ca,0x5ca,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,0x5cd,
+0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,
+0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x8e5,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,
+0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,
+0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0x5d9,0xb40,0xb40,0x9c,
+0x5d3,0x5d3,0x5d3,0x5d3,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,0x9c,
+0xb3d,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,
+0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,
+0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x9c,
+0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,
+0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x9f,0x9f,0x9f,0x9f,0x9f,0x9f,0x9f,0x9f,0x9f,0x9f,
+0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,
+0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xc60,0xa2,0xa2,0xa2,0xa2,
+0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,
+0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0xa2,0x8eb,0x8eb,0x8eb,0x8eb,
+0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0xa5,0xa5,0xa5,0x8ee,0x8ee,0x8ee,0x8ee,
+0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x5e8,0x5eb,0x5e8,0x5eb,
+0x5eb,0x5e8,0x5e8,0x5eb,0x5eb,0x5eb,0x5e8,0x5e8,0x5e8,0x5e8,0xae,0xae,0xa44,0xa44,0xa44,0xa44,
+0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xae,
+0xae,0xae,0xae,0xae,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,
+0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xae,0xae,
+0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,
+0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae,
+0x387,0x387,0x387,0x387,0x387,0x387,0x387,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,0xb1,
+0xb1,0xb1,0xb1,0x378,0x378,0x378,0x378,0x378,0xb1,0xb1,0xb1,0xb1,0xb1,0x864,0x534,0x37e,
+0x384,0x384,0x384,0x384,0x384,0x384,0x384,0x384,0x384,0x37b,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,
+0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0xb1,0x37e,0x37e,0x37e,0x37e,0x37e,0xb1,0x37e,0xb1,
+0x37e,0x37e,0xb1,0x37e,0x37e,0xb1,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0x37e,0x381,
+0x393,0x38d,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,
+0x393,0x38d,0x390,0x396,0x393,0x38d,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,
+0x393,0x38d,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,
+0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0x393,0x38d,0x390,0x396,0x393,0x38d,0x393,0x38d,0x393,
+0x38d,0x393,0x393,0x38d,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,
+0xb4,0xb4,0xb4,0xb4,0x390,0x38d,0x390,0x390,0x390,0x390,0x390,0x390,0x38d,0x390,0x38d,0x38d,
+0x390,0x390,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x38d,0x38d,0x390,0x38d,0x390,0x390,0x390,0x38d,
+0x390,0x390,0x390,0x390,0xb4,0xb4,0x390,0x390,0x390,0x390,0x38d,0x38d,0x390,0x38d,0x38d,0x38d,
+0x38d,0x390,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x390,0x390,0x38d,0x38d,0xb4,0xb4,0xb4,0xb4,
+0xb4,0xb4,0xb4,0xb4,0x936,0x936,0x936,0x936,0x936,0x936,0x936,0x936,0x936,0x936,0x936,0x936,
+0x936,0x936,0x936,0x936,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x38a,0x38a,
+0xa6b,0xabc,0xb4,0xb4,0x537,0x537,0x537,0x537,0xb7,0xb7,0xb7,0xb7,0xb7,0xb7,0xb7,0xb7,
+0xb7,0xb7,0xb7,0xb7,0x5f1,0x5f4,0x5f4,0x5fa,0x5fa,0x6ab,0x486,0x6ab,0x486,0x6ab,0x486,0x6ab,
+0x486,0x6ab,0x486,0x6ab,0x486,0x6ae,0x489,0x6ae,0x489,0xa47,0xa47,0xb52,0xb10,0x5ee,0x5ee,0x5ee,
+0x5ee,0x5f7,0x5f7,0x5f7,0x48f,0x603,0x492,0xba,0x65a,0x65a,0x564,0x564,0x600,0x6b1,0x48c,0x6b1,
+0x48c,0x6b1,0x48c,0x5fd,0x5fd,0x606,0x606,0x609,0x606,0x606,0x606,0xba,0x606,0x705,0x6d8,0x5fd,
+0xba,0xba,0xba,0xba,0x399,0x3a5,0x399,0x9d2,0x399,0xbd,0x399,0x3a5,0x399,0x3a5,0x399,0x3a5,
+0x399,0x3a5,0x399,0x3a5,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,
+0x3a5,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x3a2,
+0x39c,0xbd,0xbd,0x753,0x6cf,0x6f9,0x585,0x588,0x57c,0x6f9,0x6f9,0xc3,0x3f0,0x3f3,0x3f3,0x3f3,
+0x3f3,0x3f0,0x3f0,0xc3,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0x8c1,0x8c1,0x8c1,
+0x7c8,0x1ef,0x165,0x165,0xc3,0x55e,0x582,0x57c,0x6f9,0x6cf,0x57c,0x582,0x69c,0x46b,0x57c,0x585,
+0x46e,0x57f,0x471,0x57c,0x591,0x591,0x591,0x591,0x591,0x591,0x591,0x591,0x591,0x591,0x636,0x636,
+0x585,0x585,0x585,0x55e,0x3f9,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,
+0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,
+0x3f6,0x3f6,0x3f6,0xc3,0xc3,0xc3,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0xc3,0xc3,0x3f6,0x3f6,
+0x3f6,0x3f6,0x3f6,0x3f6,0xc3,0xc3,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0x3f6,0xc3,0xc3,0x3f6,0x3f6,
+0x3f6,0xc3,0xc3,0xc3,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,
+0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,0x942,
+0x942,0x942,0x942,0xc6,0x93f,0x93f,0x93f,0x93f,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,
+0xc6,0xc6,0xc6,0xc6,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,0x945,
+0x945,0x945,0x945,0x945,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,
+0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,
+0xcc,0xcc,0xcc,0xcc,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0xcf,0xcf,0xcf,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0x951,0x951,0x954,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
+0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
+0xcf,0xcf,0xcf,0xcf,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0xd2,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95d,0xd2,0x95d,0x95d,0xd2,0xd2,0x95d,0xd2,0xd2,0x95d,0x95d,0xd2,0xd2,0x95d,0x95d,0x95d,
+0x95d,0xd2,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95a,0x95a,0x95a,0x95a,0xd2,0x95a,
+0xd2,0x95a,0x95a,0x95a,0x95a,0xac5,0x95a,0x95a,0xd2,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0xd2,0x95d,0x95d,0x95d,0x95d,0xd2,
+0xd2,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0xd2,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0xd2,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0xd2,0x95d,
+0x95d,0x95d,0x95d,0xd2,0x95d,0x95d,0x95d,0x95d,0x95d,0xd2,0x95d,0xd2,0xd2,0xd2,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95d,0xd2,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0xb9a,0xb9a,0xd2,0xd2,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95a,0x95a,0x95a,0x957,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0xcb7,0xcb4,0xd2,0xd2,0x97b,0x97b,
+0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,
+0xd5,0x972,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,
+0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,0xd5,
+0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,0x9d8,0x9d5,
+0xcbd,0xcba,0xcbd,0xcba,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,0xd8,
+0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0x9db,0xdb,0x9db,0x9db,
+0x9db,0x9db,0xa1a,0xa1a,0xa1d,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,0xdb,
+0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,0x9de,
+0x9de,0x9de,0xa20,0xa20,0xa23,0x9ff,0x9ff,0xde,0xde,0xde,0xde,0xde,0xde,0xde,0xde,0xde,
+0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,0x9e1,
+0x9e1,0x9e1,0xa26,0xa26,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,0xe1,
+0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0x9e4,0xe4,0x9e4,0x9e4,
+0x9e4,0xe4,0xa29,0xa29,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,0xe4,
+0xb9d,0xb9d,0xb9d,0xb9d,0xb9d,0xc75,0xc12,0xcc0,0xcc0,0xcc0,0xcc0,0xe7,0xe7,0xe7,0xe7,0xe7,
+0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,0x9e7,
+0x9e7,0x9e7,0xa65,0xa0b,0xa65,0xa0b,0xa65,0xa0b,0xe7,0xe7,0xe7,0xe7,0x9ea,0x9ea,0x9ea,0x9ea,
+0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0x9ea,0xacb,0xacb,0xacb,0xacb,
+0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,
+0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xacb,0xea,0xea,0xea,0xb28,0xb28,0xb28,0xb2e,
+0xb2e,0xb2e,0xb2e,0xb28,0xb28,0xb2e,0xb2e,0xb2e,0xea,0xea,0xea,0xea,0xb2e,0xb2e,0xb28,0xb2e,
+0xb2e,0xb2e,0xb2e,0xb2e,0xb2e,0xb2b,0xb2b,0xb2b,0xea,0xea,0xea,0xea,0xac8,0xea,0xea,0xea,
+0xb37,0xb37,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb4c,0xb5e,0xb5e,0xb5e,0xb5e,
+0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xed,0xed,
+0xb5e,0xb5e,0xb5e,0xb5e,0xb5e,0xed,0xed,0xed,0xed,0xed,0xed,0xed,0xed,0xed,0xed,0xed,
+0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xae9,0xba6,0xba6,
+0xba6,0xba6,0xba6,0xba6,0xcc3,0xcc3,0xcc3,0xcc3,0xcc3,0xcc3,0xcc3,0xf0,0xf0,0xf0,0xf0,0xf0,
+0xcc3,0xcc3,0xcc3,0xcc3,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
+0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
+0xf0,0xf0,0xf0,0xf0,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,
+0xf3,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,
+0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xf3,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,
+0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xf3,0xaef,0xaef,0xf3,0xaef,
+0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xf3,0xf3,
+0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xaef,0xf3,0xf3,
+0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,
+0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,
+0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,
+0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xf6,0xf6,0xf6,0xf6,0xf6,
+0xb0a,0xb0a,0xb0a,0xf9,0xf9,0xf9,0xf9,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,
+0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,
+0xf9,0xf9,0xf9,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf5,0xaf8,0xaf8,0xaf8,0xaf8,
+0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,
+0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xaf8,0xfc,0xb0d,0xafe,0xafe,0xafe,0xafe,
+0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,
+0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xafe,0xff,0xff,0xb01,0xb01,0xb01,0xb01,
+0xb01,0xb01,0x102,0x102,0xb01,0x102,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,
+0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0xb01,0x102,0xb01,
+0xb01,0x102,0x102,0x102,0xb01,0x102,0x102,0xb01,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,
+0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0x105,
+0x105,0x105,0x105,0x105,0x105,0x105,0x105,0x105,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,
+0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0xbb2,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,
+0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0x10e,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,
+0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xbb8,0xc2d,
+0xc2d,0xc30,0xc30,0xc30,0x111,0x111,0xbfd,0xbb5,0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,
+0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,0xc66,0x114,0x114,0x114,0x114,0x114,0x114,0x114,0x114,
+0x114,0x114,0x114,0x114,0x114,0x114,0x114,0x114,0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,
+0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,0xa59,0xc33,0xc33,0xc33,0xc33,0xd14,0xd14,0xd14,0xd14,
+0xd14,0xd14,0xd14,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,
+0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,0x117,
+0x117,0x117,0xd14,0xd14,0xbc1,0xbbe,0xbc1,0xbbe,0xbbe,0xbbb,0xbbb,0xbbb,0xbbb,0xbbb,0xbbb,0x11a,
+0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0x11a,0xc00,0xc00,0xc00,
+0xc00,0xbbb,0xc00,0xc00,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,
+0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0x11d,0x11d,0x11d,0x11d,0x11d,
+0x11d,0x11d,0x11d,0x11d,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0x11d,0xbc4,0xbc4,0xbc4,0xbc4,
+0xbc4,0xbc4,0xbc4,0x11d,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0xbc4,0x11d,0xbc4,0xbc4,0xbc4,0xbc4,
+0xbc4,0xbc4,0xbc4,0x11d,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,0xbca,
+0xbca,0xbca,0xbca,0xbca,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0xbc7,0x120,0x120,
+0x120,0x120,0x120,0x120,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0x123,0x123,0x123,0x123,0x123,0x123,
+0x123,0x123,0x123,0x123,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,
+0xbf4,0xbf4,0xbf4,0xbf4,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,
+0xbd3,0xbd3,0xbd3,0x126,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,
+0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,0xbd0,
+0xbd0,0xbd0,0xbd0,0x126,0xbd9,0xc39,0xc39,0xc39,0x129,0xc39,0xc39,0x129,0x129,0x129,0x129,0x129,
+0xc39,0xc39,0xc39,0xc39,0xbd9,0xbd9,0xbd9,0xbd9,0x129,0xbd9,0xbd9,0xbd9,0x129,0xbd9,0xbd9,0xbd9,
+0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,0xbd9,
+0xbd9,0xbd9,0xbd9,0xbd9,0x129,0x129,0x129,0x129,0xc36,0xc36,0xc36,0x129,0x129,0x129,0x129,0xc3c,
+0xbd6,0xbd6,0xbd6,0xbd6,0xbd6,0xbd6,0xbd6,0xbd6,0x129,0x129,0x129,0x129,0x129,0x129,0x129,0x129,
+0xc03,0xc03,0xc03,0xc03,0xc03,0xc03,0xc03,0xc03,0xbd6,0x129,0x129,0x129,0x129,0x129,0x129,0x129,
+0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,
+0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xbdc,0xcc6,0xcc6,0xcc6,0xcc6,0x12c,0x12c,0x12c,0x12c,0x12c,
+0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0x12f,0x12f,0x12f,0x12f,0x12f,0x12f,
+0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,0xc87,
+0xc87,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc87,0xc87,0x12f,0x12f,0x12f,0x12f,0x12f,0x12f,
+0xc72,0xc72,0xc72,0xc72,0xc72,0xc72,0xc72,0xc72,0xc72,0xc72,0x12f,0x12f,0x12f,0x12f,0xc84,0xc84,
+0xbdf,0xbdf,0xbdf,0xbdf,0x132,0x132,0x132,0x132,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,
+0xc06,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0x132,0x132,0x132,0x132,0x132,0x132,0x132,0x132,0x132,0x132,
+0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc81,0xc09,0xc09,
+0xc09,0xc09,0xc09,0xc09,0xc09,0xc09,0xbeb,0xc0c,0x135,0x135,0x135,0x135,0xc81,0xc81,0x135,0x135,
+0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,
+0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,0x135,
+0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0xbf7,
+0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,0x13b,
+0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,0xa2f,
+0xc6c,0xc15,0xc15,0xc6c,0xc6c,0xc57,0xc57,0xc78,0xc18,0xc69,0x13e,0x13e,0x13e,0x13e,0x13e,0x13e,
+0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xd17,0xd17,0xd17,0xd17,0xd17,
+0xd17,0xd17,0xd17,0xd17,0xccf,0xccf,0xcc9,0xcc9,0xd2f,0xd29,0xcd2,0x141,0x141,0x141,0x141,0x141,
+0xd23,0xd23,0xd1a,0xd23,0xd26,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0x144,0x144,0x144,0x144,
+0xd35,0xd35,0xd35,0xd35,0xd35,0xd35,0xd35,0xd35,0xd35,0xd35,0xcff,0xcff,0xcf9,0xcfc,0xcff,0xcff,
+0xcf9,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xd1d,0xd1d,0xd1d,0xd1d,0xd1d,
+0xd1d,0xd1d,0xd1d,0xd1d,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0xcd5,0x144,0x144,0x144,
+0xce1,0xcde,0xce1,0xce1,0xce1,0xcde,0xcde,0xce1,0xcde,0xce1,0xcde,0xce1,0xcde,0x147,0x147,0x147,
+0x147,0x147,0x147,0x147,0xcde,0xce1,0xcde,0xcde,0x147,0x147,0x147,0x147,0x147,0x147,0x147,0x147,
+0xce4,0xce4,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,
+0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,0x14a,
+0x14a,0x14a,0x14a,0x14a,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,
+0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xd08,0xd08,0xd2c,0xd2c,0x14d,0x14d,0x14d,0x14d,
+0x14d,0x14d,0x14d,0x14d,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,
+0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xced,0xcea,0xcea,0xcea,0xcea,0x150,0x150,
+0x150,0x150,0x150,0xd02,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,
+0xcf0,0xcf0,0xcf0,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,
+0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,0x153,
+0x153,0x153,0x153,0x153,0xcf3,0xcf3,0xcf3,0x156,0x156,0x156,0x156,0x156,0x156,0x156,0x156,0x156,
+0x156,0x156,0x156,0x156,0xd05,0xd05,0xd05,0xd05,0x156,0x156,0x156,0x156,0x156,0x156,0x156,0x156,
+0x156,0x156,0x156,0x156,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,
+0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0xcf6,0x159,0x159,0x159,0x159,0x159,0x159,0x159,0x159,0x159,0x159,
+0x159,0x159,0x159,0x159,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,
+0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,
+0x15c,0x15c,0x15c,0x15c,0x15c,0x15c,0x765,0x765,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,
+0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x15f,
+0x15f,0x15f,0x15f,0x15f,0x15f,0x15f,0x15f,0x15f,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,
+0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,
+0x978,0x978,0x978,0x978,0x978,0x978,0x162,0x162,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,
+0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,
+0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x168,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,
+0x1d4,0x1d4,0x16e,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,0x981,
+0x981,0x981,0x981,0x981,0x981,0x981,0x981,0xb07,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,
+0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x171,0x369,0x369,0x369,
+0x369,0x369,0x369,0x369,0x369,0x369,0x369,0x369,0x22b,0x22b,0x225,0x225,0x3c9,0x225,0x22e,0x18f,
+0x44a,0x18f,0x18f,0x18f,0x44a,0x18f,0x22e,0x22e,0x192,0x231,0x225,0x225,0x225,0x225,0x225,0x225,
+0x18c,0x18c,0x18c,0x18c,0x228,0x18c,0x225,0x867,0x195,0x195,0x3de,0x2fd,0x60c,0x60c,0x60c,0x43e,
+0x453,0x453,0x522,0x522,0x522,0x522,0x522,0x8ca,0x6c3,0x6b4,0x6c6,0x6c9,0x6ba,0x6c3,0x6b7,0x6b7,
+0x2fd,0x70b,0x70b,0x195,0x627,0x624,0x3e1,0x303,0x432,0x432,0x435,0x435,0x435,0x435,0x435,0x56a,
+0x435,0x435,0x435,0x74d,0x52b,0x52b,0x525,0x525,0x444,0x56d,0x438,0x441,0x423,0x198,0x19b,0x300,
+0x711,0x714,0x68d,0x70b,0x711,0x711,0x68d,0x70b,0x31e,0x31e,0x333,0x6cc,0x31b,0x1a7,0x31e,0x32a,
+0x31b,0x6cc,0x32d,0x333,0x333,0x333,0x32d,0x32d,0x333,0x333,0x333,0x1ad,0x31b,0x333,0x6f3,0x31b,
+0x327,0x333,0x333,0x333,0x333,0x333,0x31b,0x31b,0x321,0x1a7,0x1aa,0x31b,0x333,0x31b,0x3e4,0x31b,
+0x333,0x324,0x339,0x1b0,0x333,0x333,0x327,0x32d,0x333,0x333,0x336,0x333,0x32d,0x330,0x330,0x330,
+0x330,0x84c,0x849,0xab0,0xb91,0x9b7,0x9ba,0x9ba,0x1b9,0x1b9,0x1b9,0x1b9,0x1b9,0x1b9,0x1b9,0x1b9,
+0x1b9,0x1b9,0x1b9,0x1b9,0x345,0x345,0x345,0x345,0x1b6,0x1b6,0x1b6,0x1b6,0x1b6,0x1b6,0x1b6,0x1b6,
+0x1b6,0x1b6,0x33f,0x33f,0x33f,0x33f,0x33f,0x33f,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x348,
+0x348,0x348,0x348,0x348,0x348,0x34b,0x351,0x351,0x348,0x348,0x1bf,0x348,0x1bf,0x348,0x348,0x348,
+0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x1c2,0x354,0x1c2,0x1c2,0x357,0x354,0x354,0x1c2,
+0x1c2,0x357,0x354,0x1c2,0x357,0x354,0x354,0x1c2,0x354,0x1c2,0x6ea,0x6e7,0x354,0x1c2,0x354,0x354,
+0x354,0x354,0x1c2,0x354,0x354,0x1c2,0x1c2,0x1c2,0x1c2,0x354,0x354,0x1c2,0x357,0x1c2,0x357,0x1c2,
+0x1c2,0x1c2,0x1c2,0x1c2,0x1c8,0x35a,0x1c2,0x35a,0x35a,0x354,0x354,0x354,0x1c2,0x1c2,0x1c2,0x1c2,
+0x354,0x354,0x354,0x354,0x1c2,0x1c2,0x354,0x354,0x354,0x357,0x354,0x354,0x357,0x354,0x354,0x357,
+0x1c2,0x357,0x354,0x354,0x1c2,0x354,0x354,0x354,0x354,0x354,0x1c2,0x354,0x354,0x354,0x354,0x354,
+0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x1c5,0x1c2,0x357,0x354,0x1c2,0x1c2,0x1c2,0x1c2,
+0x354,0x354,0x1c2,0x1c2,0x354,0x357,0x1c5,0x1c5,0x357,0x357,0x354,0x354,0x357,0x357,0x354,0x354,
+0x357,0x357,0x354,0x354,0x354,0x354,0x354,0x354,0x357,0x357,0x1c2,0x1c2,0x357,0x357,0x1c2,0x1c2,
+0x357,0x357,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x1c2,0x354,0x354,
+0x354,0x1c2,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x1c2,0x354,0x354,0x354,0x354,0x354,0x354,
+0x357,0x357,0x357,0x357,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,
+0x354,0x354,0x354,0x1c2,0x35d,0x855,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x360,0x360,0x360,0x360,
+0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x1cb,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,
+0x35d,0x35d,0x35d,0x35d,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,
+0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1d1,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,
+0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,
+0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1ce,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,
+0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d7,0x1d4,0x1d4,0x1d4,0x1d4,
+0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1d4,0x1da,0x1da,0x1da,0x1da,
+0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,
+0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x369,0x369,0x369,0x369,
+0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,0x1da,
+0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,0x1dd,
+0x36c,0x36c,0x1dd,0x1dd,0x1dd,0x1dd,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,0x9c9,
+0x1e0,0x1e0,0x36f,0x1e0,0x1e0,0x1e0,0x1e0,0x1e0,0x1e0,0x1e0,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,
+0x36f,0x36f,0x1e0,0x1e0,0x36f,0x36f,0x1e0,0x1e3,0x36f,0x36f,0x36f,0x36f,0x1e0,0x1e0,0x36f,0x36f,
+0x1e0,0x1e3,0x36f,0x36f,0x36f,0x36f,0x1e0,0x1e0,0x1e0,0x36f,0x36f,0x1e0,0x36f,0x36f,0x1e0,0x1e0,
+0x1e0,0x1e0,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,
+0x36f,0x36f,0x1e0,0x1e0,0x1e0,0x1e0,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x36f,0x1e0,
+0x85b,0x85b,0x85b,0x85b,0x85b,0x85b,0x85b,0x85b,0x9cc,0x9cc,0x9cc,0x9cc,0x9cc,0x9cc,0x9cc,0x9cc,
+0x372,0x372,0x372,0x372,0x372,0x1e6,0x1e6,0x372,0x372,0x1e6,0x372,0x372,0x372,0x372,0x1e6,0x1e6,
+0x372,0x372,0x372,0x372,0xa74,0xa74,0x97e,0x97e,0xb97,0x85e,0x372,0x372,0x1e6,0x372,0x1e6,0x372,
+0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,
+0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x1e6,0x1e6,0x372,0x1e6,
+0x1e6,0x1e6,0x372,0x1e6,0x1e6,0x1e6,0x1e6,0x372,0x1e6,0x1e6,0x372,0x1e9,0x85e,0x85e,0x9cf,0x9cf,
+0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0x9cf,0xb97,0xb97,0x207,0x3b7,0x207,0x1fe,
+0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x204,0x3b4,0x207,0x3b7,
+0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x3b7,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x3bd,0x3b4,
+0x207,0x1fe,0x207,0x3b7,0x207,0x1fe,0x207,0x1fe,0x207,0x3b4,0x3c0,0x3ba,0x207,0x1fe,0x207,0x1fe,
+0x3b4,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x3c0,0x3ba,0x3bd,0x3b4,0x207,0x3b7,0x207,0x1fe,0x207,
+0x3b7,0x3ba,0x3bd,0x3b4,0x207,0x3b7,0x207,0x1fe,0x207,0x1fe,0x3bd,0x3b4,0x207,0x1fe,0x207,0x1fe,
+0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x3bd,0x3b4,0x207,0x1fe,0x207,0x3b7,
+0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x1fe,0x207,0x207,0x1fe,0x207,
+0x1fe,0x207,0x1fe,0x201,0x20a,0x216,0x216,0x20a,0x216,0x20a,0x216,0x216,0x20a,0x216,0x216,0x216,
+0x20a,0x20a,0x216,0x216,0x216,0x216,0x20a,0x216,0x216,0x20a,0x216,0x216,0x216,0x20a,0x20a,0x20a,
+0x216,0x216,0x20a,0x216,0x219,0x20d,0x216,0x20a,0x216,0x20a,0x216,0x216,0x20a,0x216,0x20a,0x20a,
+0x216,0x20a,0x216,0x219,0x20d,0x216,0x216,0x216,0x20a,0x216,0x20a,0x216,0x216,0x20a,0x20a,0x213,
+0x216,0x20a,0x20a,0x20a,0x213,0x213,0x213,0x213,0x21c,0x21c,0x210,0x21c,0x21c,0x210,0x21c,0x21c,
+0x210,0x219,0x3c3,0x219,0x3c3,0x219,0x3c3,0x219,0x3c3,0x219,0x3c3,0x219,0x3c3,0x219,0x3c3,0x219,
+0x3c3,0x20a,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x216,0x20a,0x219,0x20d,0x219,0x20d,0x219,0x20d,
+0x219,0x20d,0x219,0x20d,0x20d,0x21c,0x21c,0x210,0x219,0x20d,0x7d4,0x7d4,0x7d7,0x7d1,0x219,0x20d,
+0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,
+0x219,0x20d,0x219,0x20d,0x219,0x20d,0x219,0x20d,0x7d7,0x7d1,0x7d7,0x7d1,0x7d4,0x7ce,0x7d7,0x7d1,
+0xb61,0xb64,0xc8d,0xc90,0xc90,0xc90,0xc90,0xc8d,0xc90,0xc8d,0xc90,0xc8d,0xc90,0xc8d,0xc90,0xc8d,
+0x21f,0x3c6,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,
+0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,
+0x222,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x21f,0x7da,0x7da,0x7da,
+0x7da,0x7da,0xa7a,0xa7a,0x234,0x234,0x234,0x234,0x234,0x234,0x234,0x234,0x234,0x22e,0x22e,0x22e,
+0x22e,0x22e,0x22e,0x22e,0x234,0x234,0x234,0x234,0x234,0x225,0x225,0x225,0x225,0x225,0x7dd,0x7dd,
+0x7dd,0x7dd,0x7e0,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,0xa7d,
+0xa7d,0xa7d,0xa7d,0xa7d,0x255,0x7e3,0x23d,0x23a,0x23d,0x23a,0x23d,0x23a,0x23d,0x23a,0x23d,0x23a,
+0x23d,0x23a,0x23d,0x23a,0x25b,0x25b,0x252,0x24c,0x93c,0x939,0x987,0xa83,0xa80,0xa86,0xa83,0xa80,
+0xb67,0xb6a,0xb6a,0xb6a,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,
+0x3d2,0x3d2,0x3d2,0x3d2,0x7e9,0x3d5,0x264,0x267,0x264,0x264,0x264,0x267,0x264,0x264,0x264,0x264,
+0x267,0x7e9,0x267,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,
+0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26d,0x267,0x26a,0x264,0x26a,0x264,
+0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,
+0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x264,0x26a,0x26d,0x267,0x26a,
+0x264,0x993,0x990,0x26a,0x264,0x993,0x990,0x26a,0x264,0x993,0x990,0xc96,0x26d,0x267,0x26d,0x267,
+0x26a,0x264,0x26d,0x267,0x26a,0x264,0x26d,0x267,0x26d,0x267,0x26d,0x267,0x26a,0x264,0x26d,0x267,
+0x7ef,0x7e9,0x26d,0x267,0x26d,0x267,0x26d,0x267,0x26d,0x267,0xb70,0xb6d,0x26d,0x267,0xc99,0xc96,
+0xc99,0xc96,0xc99,0xc96,0x7ef,0x3db,0x26a,0x26d,0x26a,0x26a,0x26a,0x26d,0x26a,0x26a,0x26a,0x26a,
+0x26d,0x7ef,0x26d,0x26a,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3db,0x3d8,0x3d8,
+0x3d8,0x3d8,0x3d8,0x3d8,0x29d,0x29a,0x29d,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x7f5,0x29a,0x29a,0x29a,0x29d,0x558,0x29a,0x4aa,0x4aa,0x4aa,0x4aa,0x4aa,0x4aa,
+0x4aa,0x291,0x4a7,0x4ad,0x65d,0x65d,0x65d,0x65d,0x65d,0x65d,0x65d,0x65d,0x65d,0x65d,0x555,0x660,
+0x660,0x297,0x996,0x996,0x4a1,0x29a,0x29a,0x29a,0x29a,0x2a0,0x2a0,0x2a0,0x2a0,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x29a,0x4ad,0x4aa,0x4aa,0x4aa,0x4aa,0x2a3,0x2a3,0x4aa,0x4aa,0x297,0x4ad,0x4ad,
+0x4ad,0x4aa,0xa8f,0xa8f,0x663,0x663,0x663,0x663,0x663,0x663,0x663,0x663,0x663,0x663,0x7f5,0x7f5,
+0x7f5,0x7f2,0x7f2,0xa8f,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,0x29a,
+0x29a,0x29a,0x29a,0x29a,0x7f5,0x7f5,0x29a,0x29a,0x29a,0x29a,0x29a,0x7f5,0x2e5,0x2e5,0x2e5,0x2e5,
+0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,
+0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2e5,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,
+0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2ee,0x2e8,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2f7,0x2f7,0x2f7,0x2f7,
+0x2f7,0x2f7,0x2f7,0x2f7,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x2fa,0x306,0x2fd,0x2fd,0x2fd,
+0x615,0x68a,0x456,0xa4a,0x8f4,0x8f4,0x846,0x846,0x846,0x846,0x9a2,0x9a2,0x9a2,0x9a2,0x9a8,0xaaa,
+0xaad,0xb88,0xbfa,0x9a5,0xbfa,0xbfa,0xbfa,0xbfa,0xb88,0xbfa,0xbfa,0x9fc,0x34e,0x348,0x348,0x34e,
+0x348,0x348,0x34e,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x351,0x348,0x348,0x348,0x348,0x348,
+0x348,0x348,0x348,0x348,0x3ea,0x3ea,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x348,0x3ea,
+0x348,0x348,0x348,0x852,0x852,0x852,0x852,0x852,0x852,0x852,0x852,0x852,0x9bd,0x9bd,0x9bd,0x9bd,
+0x9bd,0x9bd,0x9bd,0x9bd,0x9bd,0x9bd,0x9bd,0x9bd,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,
+0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,
+0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x354,0x357,0x357,0x357,0x357,0x354,0x354,0x354,0x354,
+0x354,0x354,0x357,0x357,0x357,0x357,0x354,0x354,0x354,0x354,0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,
+0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,0x9c0,0x360,0x360,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,
+0x35d,0x6a2,0x477,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,
+0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,
+0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x35d,0x855,0x9c6,0x855,0x855,0x855,0x363,0x363,0x363,0x363,
+0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,
+0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x363,0x372,0x372,0x372,0x372,
+0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,
+0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x372,0x393,0x393,0x393,0x393,
+0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,
+0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x38a,0x38a,0x38a,0x38a,0x38a,0x38a,
+0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,
+0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x396,0x393,0x38d,
+0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,
+0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x393,0x38d,0x393,0x38d,
+0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,
+0x390,0x396,0x393,0x38d,0x390,0x396,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x390,0x396,
+0x390,0x396,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,0x393,0x38d,
+0x390,0x393,0x38d,0x390,0x393,0x38d,0x390,0x396,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,
+0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,
+0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,
+0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,
+0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x390,0x390,0x390,0x390,0x390,0x390,
+0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x38d,0x393,0x696,0x45f,0x390,0x390,0x38d,0x390,
+0x38d,0x390,0x38d,0x38d,0x390,0x38d,0x38d,0x390,0x38d,0x390,0x38d,0x38d,0x390,0x38d,0x390,0x390,
+0x38d,0x38d,0x38d,0x390,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,
+0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,0x38d,
+0x390,0x390,0x38d,0x38d,0x390,0x38d,0x390,0x38d,0x38d,0x38d,0x38d,0x38d,0x390,0x390,0x390,0x390,
+0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,
+0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x390,0x396,
+0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,
+0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,
+0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,0x396,
+0x396,0x396,0x396,0x396,0x396,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,0x393,
+0x3a2,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x3a2,
+0x39c,0x39f,0x3a5,0x3a2,0x39c,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,
+0x3a5,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,
+0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,
+0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3a5,0x3a2,0x39c,0x39f,0x3d8,0x3d8,0x3d8,0x3d8,
+0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d8,0x3d2,0x3d2,0x3d2,0x3d2,
+0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d5,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0x3d2,0xa08,0x468,0x699,0x462,
+0x465,0x62a,0x3fc,0x633,0x633,0x633,0x633,0x633,0x633,0x633,0x633,0x633,0x630,0x3fc,0x3fc,0x3fc,
+0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,
+0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x3fc,0x62d,0x62d,
+0x78c,0x78c,0xc1b,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,0x78c,
+0x49e,0x49e,0x49e,0x49e,0x49e,0x49e,0x49e,0x49e,0x49e,0x49e,0xd0b,0x49e,0x49e,0x49e,0x429,0x49e,
+0x57c,0x59d,0x59d,0x59d,0x59d,0x59d,0x59d,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,
+0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x597,0x69c,0x585,0x46b,0x58b,0x58e,
+0x588,0x59a,0x59a,0x59a,0x59a,0x59a,0x59a,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,
+0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x594,0x69c,0x585,0x46b,0x585,0xa62,
+0x579,0x480,0x483,0x5a6,0x5a0,0x63c,0x5ac,0x5b2,0x6a5,0x47a,0x6a5,0x47a,0x6a8,0x47d,0x6a8,0x47d,
+0x6a5,0x47a,0x5a6,0x5a6,0x6a5,0x47a,0x6a5,0x47a,0x6a5,0x47a,0x6a5,0x47a,0x639,0x6a8,0x47d,0x47d,
+0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,
+0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,0x53a,
+0x543,0x543,0x53a,0x53d,0x53d,0x540,0x8c4,0x8c4,0x8c4,0x8c4,0x8c4,0x8c4,0x8c4,0x8c4,0x8c4,0xa32,
+0xb31,0xb31,0xb31,0xb31,0xb31,0xb31,0xb31,0xb31,0xc4e,0xc4e,0xc4e,0xc4e,0xc5a,0xb3a,0xb3a,0xb3a,
+0x5a6,0x5b2,0x5b2,0x5b2,0x5b2,0x5b2,0x5b2,0x5b2,0x5b2,0x5b2,0x546,0x546,0x546,0x546,0x546,0x546,
+0x5a9,0x5af,0x5af,0x5af,0x5af,0x5af,0x5a3,0x5a0,0x8e2,0x8e2,0x8e2,0xa50,0xa4d,0xa35,0x8df,0x576,
+0x5b8,0x5b5,0x5b8,0x642,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b8,0x5b5,0x5b5,0x5b5,0x5b5,0x5b5,0x5b5,
+0x5b8,0x5b8,0x5b5,0x5b8,0x5b8,0x5b5,0x5b8,0x5b8,0x5b5,0x5b8,0x5b8,0x5b5,0x5b8,0x5b8,0x5b5,0x5b5,
+0xa56,0x651,0x5bb,0x651,0x5bb,0x651,0x5bb,0x651,0x5bb,0x651,0x5bb,0x5bb,0x5be,0x5bb,0x5be,0x5bb,
+0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,
+0x5be,0x5bb,0x5be,0x651,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5be,0x5bb,0x5bb,0x5bb,0x5bb,0x5bb,0x5bb,
+0x5be,0x5be,0x5bb,0x5be,0x5be,0x5bb,0x5be,0x5be,0x5bb,0x5be,0x5be,0x5bb,0x5be,0x5be,0x5bb,0x5bb,
+0x5bb,0x5bb,0x5bb,0x651,0x5bb,0x651,0x5bb,0x651,0x5bb,0x5bb,0x5bb,0x5bb,0x5bb,0x5bb,0x651,0x5bb,
+0x5bb,0x5bb,0x5bb,0x5bb,0x5be,0x651,0x651,0x5be,0x5be,0x5be,0x5be,0x64b,0x64e,0x654,0x657,0xa3b,
+0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,
+0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,
+0x5c7,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,
+0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5c4,0x5dc,0x5dc,0x5dc,0x5dc,
+0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,
+0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0x5dc,0xb43,0xb43,0xc5d,0x5d0,0x5d3,0x5d3,0x5d3,0x5d3,
+0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,
+0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0x5d3,0xb3d,0xb3d,0xb3d,0xb3d,
+0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,
+0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,0x5d6,
+0x5d6,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,0xa3e,
+0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,
+0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,
+0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0xb46,
+0xb46,0xb46,0xb46,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,
+0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,
+0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0x5df,0xb46,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,
+0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,
+0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0x5e2,0xb46,0xb46,0x5e5,0x5e5,0x5e5,0x5e5,
+0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,
+0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e5,0x5e8,0x5e8,0x5e8,0x5e8,
+0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,
+0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5eb,0x5eb,
+0x5e8,0x5eb,0x5e8,0x5eb,0x5eb,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5e8,0x5eb,
+0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,
+0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,0x756,
+0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,
+0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,0x75c,
+0x762,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,
+0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,0x75f,
+0x75f,0x75f,0x75f,0x75f,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,
+0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,
+0x76e,0x76e,0x768,0x768,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,
+0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,
+0x771,0x771,0x76b,0x76b,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,
+0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,0x76e,
+0x76e,0x76e,0x76e,0x76e,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,
+0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,0x771,
+0x771,0x771,0x771,0x771,0x777,0x786,0x786,0x786,0x786,0x774,0x786,0x786,0x7ad,0x786,0x786,0x780,
+0x7aa,0x7a7,0x7a7,0x7a7,0x7a7,0x7a7,0x7ad,0x774,0x7a4,0x774,0x774,0x774,0x79b,0x79b,0x774,0x774,
+0x774,0x774,0x774,0x774,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x7b0,0x774,0x774,
+0x774,0x774,0x774,0x774,0x774,0x774,0x774,0x774,0x780,0x79b,0x774,0x79b,0x774,0x79b,0x7b3,0x789,
+0x7b3,0x789,0x7a1,0x7a1,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,
+0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,0x7b9,
+0x7b9,0x7b9,0x7b9,0x7b9,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,
+0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,0x7bc,
+0x7bc,0x7bc,0x7bc,0x7bc,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,
+0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,0x7bf,
+0x7bf,0x7bf,0x7bf,0x7bf,0x7c2,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,
+0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,
+0x7c2,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,
+0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x7c5,0x984,0xa77,0x7d4,0x7ce,
+0x7d4,0x7ce,0x7d7,0x7d1,0x7d7,0x7d1,0x7d7,0x7d1,0x7d7,0x7d1,0x7d7,0x7d1,0x7d7,0x7d1,0x7d7,0x7d1,
+0xa77,0xa77,0xa77,0xb61,0xb61,0xb61,0xb64,0xb64,0xb61,0xb64,0xb64,0xb61,0x804,0x804,0x804,0x804,
+0x804,0x804,0x804,0x804,0x804,0x804,0x804,0x804,0x804,0xa92,0xa92,0xa92,0x8a0,0x8a0,0x8a0,0x8a0,
+0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x8a0,0x807,0x807,0x807,0x807,
+0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,
+0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x807,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0xb85,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0xb85,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,
+0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x825,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,
+0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,
+0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x828,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,
+0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,
+0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x831,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,
+0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,
+0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x837,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x843,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,
+0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x840,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,
+0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,0x855,
+0x855,0x855,0x855,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,
+0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,
+0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x861,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,
+0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,
+0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d0,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,
+0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,
+0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8d6,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,
+0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,
+0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8e8,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,
+0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8f7,0x8eb,0x8eb,
+0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,
+0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,0x8eb,
+0x8ee,0x8ee,0xa41,0xa41,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,
+0x8ee,0x8ee,0x8ee,0x8ee,0xa41,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,0x8ee,
+0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,
+0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,0x918,
+0x930,0x930,0x930,0x933,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,
+0x930,0x930,0x930,0x930,0x91e,0x91e,0x92d,0x921,0x921,0x921,0x921,0x921,0x921,0x921,0x92d,0x92d,
+0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,
+0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,0x930,
+0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0xac2,0xac2,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,
+0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,0x948,
+0x948,0x948,0xabf,0xabf,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,
+0xafb,0xafb,0xafb,0xafb,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,
+0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,0x94b,
+0x94b,0x94b,0x94b,0x94b,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,
+0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,0x94e,
+0x94e,0x94e,0x94e,0x94e,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x954,0x954,0x954,0x954,0x954,0x954,0x954,0x963,0x969,0x96f,
+0x96f,0x96f,0x951,0x951,0x951,0x96c,0x966,0x966,0x966,0x966,0x966,0x960,0x960,0x960,0x960,0x960,
+0x960,0x960,0x960,0x96f,0x96f,0x96f,0x96f,0x96f,0x96f,0x96f,0x96f,0x951,0x951,0x96f,0x96f,0x96f,
+0x96f,0x96f,0x96f,0x96f,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x96f,0x96f,0x96f,0x96f,0x951,0x951,
+0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x951,0x954,0x954,0x954,0x954,0x954,
+0x95d,0x957,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x957,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x957,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x957,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x957,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,
+0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95d,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,
+0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95a,0x95d,0x95d,0x95d,0x95d,0x972,0x972,0x972,0x972,
+0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,
+0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x972,0x975,0x975,0x975,0x975,
+0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,
+0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x975,0x978,0x978,0x978,0x978,
+0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,
+0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x978,0x97b,0x97b,0x97b,0x97b,
+0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,
+0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x97b,0x9c6,0x9c6,0x9c6,0x9c6,
+0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,0x9c6,
+0x9c3,0x9c3,0x9c3,0x9c6,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,0x9c3,
+0x9c3,0x9c3,0x9c3,0xab3,0xab6,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,0xb94,
+0xcae,0xcae,0xcae,0xcae,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,
+0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,0x9ed,
+0x9ed,0x9ed,0x9ed,0x9ed,0x9f0,0x9f0,0x9f0,0xa5f,0xa05,0xa68,0xa0e,0xa5f,0xa05,0xa5f,0xa05,0xa5f,
+0xa05,0xa5f,0xa05,0xa5f,0xa05,0xa5f,0xa05,0xa5f,0xa05,0xa5f,0xa05,0xa5f,0xa05,0x9f0,0x9f0,0x9f0,
+0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,
+0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,
+0xa5f,0xa05,0xa5f,0xa05,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,
+0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,0x9f0,
+0xa5f,0xa05,0x9f0,0x9f0,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,
+0x9f9,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,
+0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,
+0x9f3,0x9f3,0x9f3,0x9f3,0x9f9,0x9f9,0x9f9,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,
+0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,0x9f3,
+0x9f3,0x9f3,0x9f3,0x9f3,0x9f6,0x9f3,0x9f3,0x9f3,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,
+0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,
+0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xa44,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,
+0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,
+0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xace,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xad4,0xad4,
+0xad4,0xad4,0xad4,0xad1,0xae6,0xae6,0xae6,0xae0,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,
+0xae6,0xae6,0xae6,0xae0,0xae6,0xae6,0xae6,0xae6,0xada,0xada,0xae3,0xae3,0xae3,0xae3,0xad7,0xad7,
+0xad7,0xad7,0xad7,0xadd,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,
+0xba0,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xba3,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,
+0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae0,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,0xae6,
+0xae6,0xae6,0xae6,0xae6,0xae6,0xada,0xada,0xada,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,
+0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,
+0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xadd,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,
+0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,
+0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaec,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,
+0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,
+0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xaf2,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,
+0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,
+0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xafb,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,
+0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,
+0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb04,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,
+0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,
+0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xb34,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,
+0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,
+0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xba9,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,
+0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbac,0xbac,0xbac,
+0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbac,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,
+0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,
+0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbaf,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,
+0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,
+0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbc1,0xbbe,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,
+0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,
+0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbcd,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,
+0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,
+0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbd3,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,
+0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,
+0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbdf,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,
+0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,
+0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbe2,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,
+0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,0xbe5,
+0xbe5,0xbe5,0xbe5,0xbe8,0xbe8,0xbe8,0xbe8,0xbe8,0xbf1,0xbf1,0xc48,0xbf1,0xbf1,0xbf1,0xc45,0xbf1,
+0xbf1,0xbf1,0xbf1,0xc3f,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,
+0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf1,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,
+0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,
+0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xbf4,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,
+0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,
+0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc63,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,
+0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,
+0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xc8a,0xd32,0xd32,0xd32,0xd32,0xd32,0xd32,0xd32,0xd32,
+0xd32,0xd32,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,
+0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xccc,0xd1a,0xd1a,0xd1a,0xd1a,0xd20,0xcd8,0xcdb,0xcd8,
+0xcdb,0xcd8,0xcdb,0xcd8,0xcdb,0xcd8,0xcdb,0xcd8,0xcd8,0xcd8,0xcdb,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,
+0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,0xcd8,
+0xd1d,0xd20,0xd1a,0xd1a,0xd1a,0xd1a,0xd1a,0xd23,0xd1a,0xd23,0xd20,0xd20,0xce7,0xce7,0xce7,0xce7,
+0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,
+0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xce7,0xcf0,0xcf0,0xcf0,0xcf0,
+0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,
+0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf0,0xcf3,0xcf3,0xcf3,0xcf3,
+0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,
+0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0xcf3,0x820,0x840,0x860,0,
+0,0,0,0,0x880,0x8a0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0x8c0,0x8e0,0,0,
+0,0,0,0,0,0,0,0x900,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,
+0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,
+0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x920,0x940,0x960,0x960,0x960,0x960,0x960,0x960,
+0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x980,0x9a0,
+0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,
+0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,0x960,
+0x960,0x960,0x960,0x9a0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0x900,0x9c0,0x9e0,0x9e0,0x9e0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,
+0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,
+0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa00,0xa20,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,
+0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,
+0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa40,0xa60
+};
+
+static const UTrie propsVectorsTrie={
+ propsVectorsTrie_index,
+ NULL,
+ utrie_defaultGetFoldingOffset,
+ 2688,
+ 14236,
+ 0,
+ TRUE
+};
+
+static const uint32_t propsVectors[3384]={
+0x67,0,0,0x67,0x800000,0,0x467,0,0,0x4e7,0,0,0x567,0,0,0x5e7,
+0,0,0x667,0,0,0x6e7,0,0,0x767,0,0,0x7e7,0,0,0x867,0,
+0,0x8e7,0,0,0x967,0,0,0x9e7,0,0,0xa67,0,0,0xae7,0,0,
+0xb67,0,0,0xbe7,0,0,0xc67,0,0,0xce7,0,0,0xd67,0,0,0xde7,
+0,0,0xe67,0,0,0xee7,0,0,0xf67,0,0,0xfe7,0,0,0x1067,0,
+0,0x10e7,0,0,0x1167,0,0,0x11e7,0,0,0x1267,0,0,0x12e7,0,0,
+0x1367,0,0,0x13e7,0,0,0x1467,0x800000,0,0x14e7,0,0,0x1567,0,0,0x15e7,
+0,0,0x1667,0,0,0x16e7,0,0,0x1867,0,0x4000000,0x18e7,0,0x4000000,0x1967,0,
+0x4000000,0x1be7,0,0x4000000,0x1c67,0,0x4000000,0x1d67,0,0,0x1de7,0,0,0x1e67,0,0,
+0x1f67,0,0,0x2067,0,0,0x20e7,0,0,0x21e7,0,0,0x2267,0,0,0x2367,
+0,0,0x23e7,0,0,0x2467,0,0,0x24e7,0,0,0x2567,0,0,0x27e7,0,
+0,0x2867,0,0,0x28e7,0,0,0x2967,0,0,0x2a67,0,0,0x2ae7,0,0,
+0x2b67,0x800000,0,0x2be7,0,0,0x2c67,0,0,0x2ce7,0,0,0x2de7,0,0,0x2e67,
+0,0,0x2ee7,0,0,0x3067,0x800000,0,0x30e7,0,0,0x3167,0,0,0x31e7,0,
+0,0x3267,0,0,0x32e7,0,0,0x3367,0,0x4000000,0x37e7,0,0,0x3867,0,0,
+0x39e7,0,0x4000000,0x3ae7,0,0,0x3b67,0,0,0x3be7,0,0,0x3c67,0,0,0x3d67,
+0,0,0x3de7,0,0,0x3e67,0,0,0x3f67,0,0,0x3fe7,0,0,0x4067,0,
+0,0x40e7,0,0,0x4167,0,0,0x41e7,0,0,0x4267,0,0,0x42e7,0,0,
+0x4367,0,0,0x43e7,0,0,0x4467,0,0,0x44e7,0,0,0x4567,0,0,0x45e7,
+0,0,0x4667,0,0,0x4767,0,0x4000000,0x47e7,0,0,0x4867,0,0,0x48e7,0,
+0,0x4967,0,0,0x49e7,0,0,0x4a67,0,0,0x4ae7,0,0,0x4b67,0,0,
+0x4be7,0,0,0x4c67,0,0,0x4ce7,0,0,0x4d67,0,0,0x28067,0,0,0x2af67,
+0,0,0x2afe7,0,0,0x11002b67,0x810000,0,0x1100a767,0,0,0x11041680,0x80000000,6,0x11041980,0x80000000,
+3,0x11041a00,0x80000000,0x4000000,0x11041c00,0x80000000,0,0x11048100,0x80000000,6,0x11048100,0x80000000,0xf,0x11048100,0x80000000,0x4000000,
+0x11048100,0x80000080,0x4000000,0x11048100,0x80001000,2,0x11048100,0x90003000,0x1000,0x11048119,0xf8000400,0x1040f,0x11048300,0x80001000,2,0x11048300,
+0xf8001400,0x18400,0x11048300,0xf8003400,0x18400,0x11049400,0x80000000,0x4000000,0x11049400,0x80000008,0x4000000,0x11049400,0x80000080,0x4000000,0x11049480,0x80000000,
+0xe,0x11049480,0x80000000,0xf,0x11049499,0xf8000400,0x1040f,0x11049600,0x80000000,2,0x11049600,0x80000000,0xf,0x11049600,0xf8000480,0x10405,
+0x11049619,0xf8000400,0x28401,0x11049680,0x80000000,6,0x11049680,0xf8000400,0x10402,0x11049680,0xf8000400,0x28402,0x11049700,0x80000000,0x4000000,0x11049700,
+0x80000080,0x4000000,0x11049780,0x80000080,0x4000000,0x11049780,0x80000080,0x4000001,0x11049780,0x80000080,0x4000002,0x11049800,0x80000000,0x4000000,0x11049980,0x80000000,
+2,0x11049980,0x80000000,3,0x11049980,0x80000400,0x10403,0x11049980,0x80000400,0x28403,0x11049a00,0x80000000,0x4000000,0x11049a80,0x80000000,0x4000000,
+0x11049b00,0x80000000,0x4000000,0x11049b00,0x80000080,0x4000000,0x11049b80,0x80000000,0x4000000,0x11049b80,0x80000080,0x4000000,0x11049c00,0x80000000,0,0x1104ab00,
+0x80000000,0,0x11080100,0x80000000,0x4000000,0x11080100,0xf8000400,0x10402,0x11080119,0xf8000400,0x10401,0x11080119,0xf8000400,0x28401,0x11080199,0xf8000400,
+0x10401,0x11080199,0xf8000400,0x10402,0x11080199,0xf8000400,0x28400,0x11080199,0xf8000400,0x28401,0x11080219,0xf8000400,0x10400,0x11080219,0xf8000400,0x10401,
+0x11080219,0xf8000400,0x10402,0x11080219,0xf8000400,0x18400,0x11080219,0xf8000400,0x28400,0x11080219,0xf8000400,0x28401,0x11080219,0xf8000400,0x28402,0x11080299,
+0xf8000400,0x10400,0x11080299,0xf8000400,0x18400,0x11080300,0x80001000,0,0x11080300,0x80001000,2,0x11080300,0xf8001400,0x10400,0x11080300,0xf8001400,
+0x18400,0x11080300,0xf8003400,0x18400,0x11080319,0xf8001400,0x1040f,0x11080400,0x80000040,1,0x11080407,0xf8000400,0x10400,0x11080407,0xf8000400,0x28400,
+0x1108040e,0x80001000,0,0x1108040e,0x80001000,1,0x1108040e,0x80001000,2,0x1108040e,0xe0001400,0x10402,0x1108040e,0xf8000400,0x10400,0x1108040e,
+0xf8000400,0x10401,0x1108040e,0xf8000400,0x10402,0x1108040e,0xf8000400,0x28400,0x1108040e,0xf8000400,0x28401,0x1108040e,0xf8000480,0x10402,0x1108040e,0xf8000480,
+0x28402,0x11080488,0x80000000,0,0x11080488,0xf8000400,0x10400,0x11080488,0xf8000400,0x10401,0x11080488,0xf8000400,0x28400,0x11080488,0xf8000400,0x28401,
+0x11080503,0x80000000,0,0x11080503,0x80000000,0x1024000,0x11080503,0xf8000400,0x10400,0x11080503,0xf8000400,0x10402,0x11080503,0xf8000400,0x28400,0x11080503,
+0xf8001400,0x18400,0x11080593,0x80000000,0,0x11080593,0x80000000,0x1000,0x11080593,0x80000000,0x18400,0x11080593,0x80000040,0,0x11080593,0xf8000400,
+0x18400,0x11080600,0x800000,0xc820,0x11080600,0xf8002400,0x18400,0x11080602,0x80000000,0,0x11080602,0xf8000400,0x18400,0x11080602,0xf8000400,0x18401,
+0x11080602,0xf8000400,0x18402,0x11080602,0xf8001400,0x18400,0x11080780,0x80000000,0,0x1108078a,0xf8000400,0x18400,0x1108078a,0xf8000400,0x18401,0x11080804,
+0x80000000,0,0x11080804,0xf8000400,0x18400,0x11080804,0xf8000400,0x18401,0x11080890,0xf8000400,0x18400,0x11080890,0xf8000400,0x18401,0x1108090f,0xf8000400,
+0x18400,0x1108099f,0x80000000,0,0x1108099f,0xf8000400,0x18400,0x1108099f,0xf8000400,0x18401,0x11080a23,0x80000000,0,0x11080a23,0xf8000400,0x18400,
+0x11080a23,0xf8000400,0x18401,0x11080aa4,0xf8000400,0x18400,0x11080b15,0xf8000400,0x18400,0x11080b9a,0xf8000400,0x18400,0x11080ca6,0x80000000,0,0x11080e80,
+0x80000000,0,0x11080e8c,0xf8000400,0x18400,0x11080e8c,0xf8000400,0x28400,0x11081319,0xf8000400,0x10401,0x11081319,0xf8000400,0x10402,0x11081319,0xf8000400,
+0x28401,0x1108138e,0x80001000,1,0x1108138e,0x80001000,2,0x1108138e,0xf8000400,0x10401,0x1108138e,0xf8000400,0x28401,0x11081400,0x80000000,0x4000000,
+0x11081400,0x80000000,0x4000002,0x11081400,0xd0000000,0x1c00,0x11081400,0xd0000080,0x1c00,0x11081480,0x80000000,0xe,0x11081480,0x80000000,0xf,0x11081480,
+0x80000080,0xe,0x11081480,0x80000080,0xf,0x11081480,0x80000088,0xe,0x11081480,0x80000088,0xf,0x11081600,0x80000000,0,0x11081600,0x80000000,
+2,0x11081600,0x80000000,0xf,0x11081600,0x80000080,0,0x11081600,0xf8000000,0,0x11081600,0xf8000400,0x28402,0x11081600,0xf8000480,0x10405,
+0x11081600,0xf8000480,0x18402,0x11081600,0xf8000480,0x28405,0x11081619,0xf8000400,0x28400,0x11081619,0xf8000400,0x28401,0x11081680,0x80000000,6,0x11081680,
+0xf8000400,0x10402,0x11081680,0xf8000400,0x18400,0x11081680,0xf8000400,0x28402,0x11081700,0x80000000,0x4000000,0x11081700,0x80000000,0x4000001,0x11081700,0x80000080,
+0x4000000,0x11081700,0x80000080,0x4000001,0x11081780,0x80000080,0x4000000,0x11081780,0x80000080,0x4000001,0x11081780,0x80000080,0x4000002,0x11081800,0x80000000,0x4000000,
+0x11081800,0x80000080,0x4000000,0x11081880,0x80000000,0x4000000,0x11081900,0x80000000,0x4000000,0x11081a00,0x80000000,0x4000000,0x11081a80,0x80000000,0x4000000,0x11081b00,
+0x80000000,0x4000000,0x11081b80,0x80000000,0x4000000,0x11081c00,0x80000000,0x4000000,0x11082803,0xf8000400,0x10402,0x11082813,0x80000080,5,0x11082813,0xf8000400,
+0x18401,0x11082813,0xf8000400,0x18402,0x11082813,0xf8000400,0x18405,0x11082819,0xf8000400,0x10402,0x11082882,0xe0000400,0x18408,0x11082882,0xf8000400,0x18404,
+0x11082882,0xf8000400,0x18407,0x11082882,0xf8000400,0x18408,0x11082882,0xf8000400,0x18409,0x11082a82,0xe0000400,0x18408,0x11082a82,0xf8000400,0x18404,0x11082a82,
+0xf8000400,0x18407,0x11082a82,0xf8000400,0x18408,0x11082a82,0xf8000400,0x18409,0x11088100,0x80000000,0x4000000,0x11088119,0xf8000400,0x10400,0x11088119,0xf8000400,
+0x10401,0x11088119,0xf8000400,0x28400,0x11088199,0xf8000400,0x10400,0x11088199,0xf8000400,0x10401,0x11088199,0xf8000400,0x10402,0x11088199,0xf8000400,0x28400,
+0x11088199,0xf8000400,0x28402,0x11088219,0xf8000400,0x10401,0x11088299,0xf8000400,0x10400,0x11088300,0x80001000,0,0x1108840e,0xf8000400,0x10400,0x1108840e,
+0xf8000400,0x28400,0x11088488,0xf8000400,0x10400,0x11088488,0xf8000400,0x10401,0x11088488,0xf8000400,0x28400,0x11088488,0xf8000400,0x28401,0x11089400,0x80000000,
+0x4000000,0x11089400,0x80000000,0x4000002,0x1108960e,0xf8000400,0x28401,0x11089680,0x80000000,6,0x11089700,0x80000000,0x4000000,0x11089c00,0x80000000,0x4000000,
+0x11092b80,0x80000000,0xa,0x11092b80,0x80000080,0xa,0x11092b92,0xf8000400,0x1840a,0x11092b92,0xf8800400,0x1840a,0x11092b96,0xf8000400,0x18c0a,0x110a0080,
+0x80000000,0x4000000,0x110a0080,0x80000080,0x4000000,0x110a0080,0x80001000,0x4000000,0x110a0080,0x80001080,0x4000000,0x110a0080,0xd0000000,0x1c00,0x110a0099,0xf8000400,
+0x10400,0x110a0099,0xf8000400,0x28400,0x110a0099,0xf8000700,0x10400,0x110a0099,0xf8000700,0x28400,0x110a0100,0x80000000,0x4000000,0x110a0100,0x80000080,0x4000000,
+0x110a0100,0x80001000,2,0x110c9400,0x80000008,0x4000000,0x11100080,1,0x8020020,0x11100593,0x80000008,0,0x11100780,0x80000040,0x1024000,0x11100ca6,
+0x80000040,0,0x11101400,0x80000001,0x20001,0x11101400,0x80000001,0x20002,0x11101400,0x80000008,0x4000000,0x11108100,0x800010,0xc820,0x11109400,0x80000000,
+0x4001000,0x11109400,0x80000008,0x4000000,0x11109400,0x80000018,0x4000000,0x11120080,0x80000080,0x4000000,0x11140300,0xf8001400,0x18400,0x11148100,0x80001000,2,
+0x11180080,1,0x8020020,0x11181400,1,0x801c020,0x11201400,0x80000000,0x4008000,0x11201480,0x80000080,0x800e,0x11201480,0x80000080,0x800f,0x11202880,
+0x80000000,0x4008000,0x11212b80,0x80000020,0x800a,0x11212b80,0x80000040,0xa,0x11212b80,0x80000040,0x102400a,0x1121ab80,0x80000000,0x8011,0x1121ab80,0x80000040,
+0x11,0x1121ab80,0x80000040,0x1024011,0x11220080,0x80000000,0x4008000,0x11229800,0x80000000,0x4008001,0x11229e80,0x80000000,0x4008000,0x11229e80,0x80000020,0x4008000,
+0x11229e80,0x80000040,0x4000000,0x11229e80,0x80000040,0x5024000,0x1122a980,0x80000000,0x8010,0x1122a980,0x80000020,0x8010,0x1122aa00,0x80000000,0x800c,0x1122aa00,
+0x80000040,0xc,0x1122aa00,0x80000040,0x102400c,0x11240080,0x800000,0x20,0x11240100,0x800000,0x20,0x11240488,0x50021000,0x60,0x11240593,0x50021400,
+0x60,0x11240601,0x50020400,0x60,0x11240601,0x50021400,0x60,0x11240602,0x20000,0x60,0x11240602,0x50020400,0x60,0x11240602,0x50021000,0x60,
+0x1124078a,0x50020400,0x60,0x1124078a,0x50021000,0x60,0x1124078a,0x50061000,0x60,0x1124078a,0xd0000400,0x18400,0x11240804,0x50020400,0x60,0x11240804,
+0x50021000,0x60,0x11240804,0x50061000,0x60,0x11240804,0xd0000400,0x18400,0x11240804,0xd0000400,0x18401,0x11240890,0x50020400,0x60,0x11240890,0x50021000,
+0x60,0x11240890,0x50061000,0x60,0x11240890,0xd0000400,0x18400,0x1124090f,0x50020400,0x60,0x1124090f,0x50021000,0x60,0x1124090f,0x50061000,0x60,
+0x1124090f,0xd0000400,0x18400,0x1124099f,0x50020400,0x60,0x1124099f,0x50021000,0x60,0x1124099f,0x50061000,0x60,0x1124099f,0xd0000400,0x18400,0x1124099f,
+0xd0000400,0x18401,0x11240a23,0x50020400,0x60,0x11240a23,0x50061000,0x60,0x11240a23,0xd0000400,0x18400,0x11240a23,0xd0000400,0x18401,0x11240aa4,0x50020400,
+0x60,0x11240aa4,0x50020400,0x61,0x11240aa4,0x50061000,0x60,0x11240aa4,0xd0000400,0x18400,0x11240b15,0x50020400,0x60,0x11240b15,0x50061000,0x60,
+0x11240b15,0xd0000400,0x18400,0x11240b15,0xd0000400,0x18401,0x11240b9a,0x50020400,0x60,0x11240b9a,0x50061000,0x60,0x11240b9a,0xd0000400,0x18400,0x11240b9a,
+0xd0000400,0x18401,0x11241400,0x800000,0xc820,0x11241400,0x800000,0x800c820,0x11241400,0x1800000,0xc820,0x11241401,0x820000,0x60,0x11241581,0x20000,
+0x60,0x11241581,0x50020080,0x60,0x11242813,0x50021400,0x60,0x11242901,0x50021000,0x60,0x11248381,0x50021000,0x60,0x11248381,0x50021000,0x61,
+0x11248381,0x50021400,0x60,0x11248381,0x51021000,0x61,0x11269e81,0x50021000,0x60,0x11269f01,0x50021000,0x60,0x11280080,1,0x801c040,0x112c0600,
+0x80000040,0,0x112c0600,0x80000040,0x1024000,0x112c0602,0x80000000,0,0x112c0602,0x80000040,0x1024000,0x112c1c00,0x80000000,0x4000000,0x112dab80,0x80000040,
+0x1024011,0x112e0080,0x80000040,0x5024000,0x112eaa00,0x80000040,0x102400c,0x11300100,0x80000001,0x1800b,0x11301400,0x80000001,0x2000b,0x11301400,0x80000018,0x400000b,
+0x11308381,0x50021000,0x60,0x11360080,0x80000018,0x4000000,0x11381e80,0x80000000,0,0x11399e80,0x80000001,0x20011,0x1139ab80,0x80000000,0x11,0x1139ab80,
+0x80000018,0x11,0x1139ab80,0x80000020,0x11,0x1139ab80,0x80000080,0x11,0x1139ab80,0x80001000,0x11,0x1139ab80,0x80001080,0x11,0x1139ab80,0xd0000000,
+0x1c11,0x1139ab80,0xd0000100,0x11,0x1139ab99,0xf8000400,0x10411,0x1139ab99,0xf8000400,0x28411,0x1139ab99,0xf8000500,0x10411,0x1139ab99,0xf8000500,0x28411,
+0x113a9e80,0x80000000,0,0x113a9e80,0x80000000,2,0x113a9e80,0x80000000,0x4000000,0x113a9e80,0x80000008,0x4000000,0x113a9e80,0xf8000c00,0x18000,0x113a9e80,
+0xf8002400,0x18c00,0x113a9e91,0xf8000c00,0x18000,0x113a9f14,0xf8000400,0x18000,0x113a9f14,0xf8000400,0x18001,0x113a9f96,0xf8000400,0x18c00,0x113a9f96,0xf8000400,
+0x18c01,0x113aa005,0xf8000400,0x18400,0x113aa092,0xf8000400,0x18402,0x113aa092,0xf8800400,0x18402,0x113aa100,0x80000000,0,0x113aa100,0x80000000,0xf,
+0x113aa200,0x80000000,0,0x113aa200,0x80000000,2,0x113aa200,0x80000000,3,0x113aa212,0x80000000,2,0x113aa212,0x80000000,3,0x113aa280,
+0x80000000,2,0x113aa280,0x80000000,0xd,0x113aa391,0xf8400c00,0x18000,0x113aa791,0xf8000c00,0x18001,0x113aa791,0xf8400c00,0x18000,0x113aa980,0x80000000,
+2,0x113aa980,0x80000000,0x10,0x113aa980,0x80000008,0x10,0x113aa980,0xd0000000,0x1c02,0x113aa980,0xd0000000,0x1c10,0x113aaa00,0x80000000,0xc,
+0x113aaa00,0x80000008,0xc,0x113aaa00,0x80000040,0xc,0x113aaa00,0x80000080,0xc,0x113aaa00,0x80000098,0xc,0x113c9400,0x80000000,0x4000002,0x11400400,
+0x80000040,0x1401,0x11400500,0x80000040,0x1025400,0x11401400,0x80000080,0x4001400,0x11420080,0x80000040,0x4001000,0x11420080,0x80000040,0x4001400,0x11420080,0x80000040,
+0x5005400,0x11440080,1,0x801c0a0,0x11481400,0x80000040,0x5024000,0x11481400,0x80000040,0x5024002,0x11492b80,0x80000010,0xa,0x11492b80,0xf0001400,0x18c0a,
+0x11492b80,0xf8003400,0x18c0a,0x11492b96,0xf8000400,0x18c0a,0x1149ab80,0x80000040,0x11,0x114a9e80,0x80000008,0x4000000,0x114a9e91,0xf8002400,0x18400,0x114a9f00,
+0xe0001000,0xc02,0x114a9f14,0xf8000400,0x18000,0x114a9f14,0xf8002400,0x18000,0x114a9f14,0xf8002400,0x18001,0x114a9f80,0x80000010,0,0x114a9f80,0xf8003400,
+0x18c00,0x114a9f96,0xf8000400,0x18c00,0x114a9f96,0xf8002400,0x18c00,0x114a9f96,0xf8002400,0x18c01,0x114aaa00,0x80000040,0xc,0x114c0600,0xd0000000,0x15800,
+0x114c0602,0x80000000,0x15800,0x114c0602,0xd0000000,0x15800,0x114c078a,0xd0000000,0x15800,0x114c0804,0xd0000000,0x15800,0x114c0890,0xd0000000,0x15800,0x114c090f,
+0xd0000000,0x15800,0x114c099f,0xd0000000,0x15800,0x114c0a23,0xd0000000,0x15800,0x114c0aa4,0xd0000000,0x15800,0x114c0b15,0xd0000000,0x15800,0x114c0b9a,0xd0000000,
+0x15800,0x114c0ca6,0xd0000000,0x15800,0x114c0d18,0xd0000000,0x15800,0x114e0080,0xd0000300,0x15800,0x11501400,0x80000000,0x4008000,0x11501400,0x80000020,0x4008000,
+0x11501480,0x80000080,0x800e,0x11501480,0x80000080,0x800f,0x11502880,0x80000000,0x4008000,0x11512b80,0x80000020,0x800a,0x1151ab80,0x80000000,0x8011,0x11520080,
+0x80000000,0x4008000,0x11529800,0x80000000,0x4008001,0x11529e80,0x80000000,0x4008000,0x11529e80,0x80000020,0x4008000,0x1152a980,0x80000000,0x8010,0x1152a980,0x80000020,
+0x8010,0x1152aa00,0x80000000,0x800c,0x11541400,0x80000000,0x4000000,0x11541400,0x80000000,0x4000002,0x11541400,0x80000080,0x4000002,0x11541500,0x80000000,0,
+0x11548100,0x80000000,0x4000000,0x11549400,0x80000000,0x4000000,0x11549400,0x80000080,0x4000000,0x11549400,0x80000080,0x4000002,0x11549600,0x80000000,2,0x1155ab80,
+0x80000000,0x11,0x11560080,0x80000000,0x4000000,0x11560100,0x80000000,0x4000000,0x1156aa00,0x80000000,0xc,0x11580804,0x80000000,0,0x11580c80,0x80000000,
+0,0x11581500,0x80000000,0,0x11581500,0x80000000,2,0x11581780,0x80000080,0x4000000,0x11581780,0x80000088,0x4000000,0x11588100,0x80000000,0x4000000,
+0x11588100,0x80000080,0x4000000,0x11589600,0x80000000,2,0x11591500,0x80000000,0,0x1159ab80,0x80000000,0x11,0x115a0080,0x80000000,0x4000000,0x115a0080,
+0x80000080,0x4000000,0x115a0100,0x80000000,0x4000000,0x115aaa00,0x80000000,0xc,0x115c0100,0x80000020,0x4008000,0x115c1400,0x80000020,0x4008000,0x115c1c00,0x80000000,
+0x4008000,0x115c9400,0x80000020,0x4008000,0x115c9400,0x80000020,0x4009000,0x115e0080,0x80000020,0x4008000,0x115e0080,0x80000020,0x4009000,0x11600ca6,0x50020400,0x60,
+0x11600ca6,0x50021000,0x60,0x11600ca6,0x50060400,0x60,0x11600ca6,0xf0000400,0x18002,0x11600ca6,0xf8000400,0x18000,0x11600ca6,0xf8002400,0x18000,0x11600ca6,
+0xfc000400,0x18000,0x11600d18,0x50020400,0x60,0x11600d18,0x50021000,0x60,0x11600d18,0xf0000400,0x18002,0x11600d18,0xf8000400,0x18000,0x11600d18,0xf8000400,
+0x18002,0x11600d18,0xf8002400,0x18000,0x11600d18,0xfc000400,0x18000,0x116a0080,0x80000001,0x8020000,0x116e0080,0x80000000,0x4000000,0x11701400,0x800000,0xc820,
+0x11740100,1,0x801c020,0x11782a80,0x800000,0xc820,0x11868f12,0xf8000400,0x18480,0x11868f12,0xf8800400,0x18480,0x11880f12,0xf8000400,0x18500,0x118c0f12,
+0xf8000400,0x18520,0x118c0f12,0xf8800400,0x18520,0x20000067,0x810000,0,0x200036e7,0x810000,0,0x20003767,0x810000,0,0x2000b6e7,0,
+0,0x2000b767,0,0,0x20080da7,0x80000000,0,0x20080da7,0xf8000400,0x18400,0x20080da7,0xf8000400,0x18401,0x20081319,0xf8000400,0x10401,
+0x20100da7,0x80000000,0,0x20100da7,0xd0000400,0x18400,0x20140da7,0x80000000,0,0x20200da7,0x80000000,0x8000,0x20240593,0x50021000,0x60,0x20240593,
+0x50021400,0x60,0x20240da7,0x50020400,0x60,0x20240da7,0x50020400,0x61,0x20240da7,0x50020400,0x62,0x20240da7,0x50021000,0x60,0x20240da7,0x50061000,
+0x60,0x20240da7,0xd0001000,0,0x202c0da7,0x80000000,0,0x202c0da7,0x80000040,0,0x20300da7,0x80000000,0xb,0x20300da7,0x80000040,0,
+0x204c0da7,0xd0000000,0x15800,0x20500da7,0x80000000,0x8000,0x20581500,0x80000000,0,0x206425e7,0x800000,0,0x20642667,0x800000,0,0x206426e7,
+0x800000,0,0x207ea512,0xf8000400,0x184c1,0x2082a512,0xf8000400,0x184e1,0x211c2b00,0x80000000,0,0x21589500,0x80000000,0,0x30080219,0xf8000400,
+0x10400,0x30080219,0xf8000400,0x10401,0x30080219,0xf8000400,0x28400,0x30080219,0xf8000400,0x28401,0x30080299,0xf8000400,0x10400,0x30080300,0x80001000,0,
+0x30080300,0xf8001400,0x18400,0x3008040e,0xf8000400,0x10400,0x30080488,0xf8000400,0x10400,0x30080488,0xf8000400,0x10401,0x30080488,0xf8000400,0x28400,0x30080488,
+0xf8000400,0x28401,0x30080602,0x80000000,0,0x30080602,0xf8000400,0x18400,0x300806a2,0x800000,0xc820,0x300806a2,0x80000000,0,0x300806a2,0x80000040,
+0,0x300806a2,0x80000040,0x1024000,0x300806a2,0xf8000400,0x18400,0x30080725,0xf8000400,0x18400,0x30080c21,0x80000000,0,0x30080c21,0xf8000400,0x18400,
+0x30080da7,0x80000000,0,0x30080da7,0xf8000400,0x18400,0x30080e1c,0x80000000,0,0x30080f8b,0x80000000,0,0x30080f8b,0x80000040,0,0x30080f8b,
+0x80000040,0x1024000,0x30080f8b,0xd0000000,0,0x30080f8b,0xf8000400,0x18400,0x30081006,0xf8000400,0x18400,0x300810a8,0x80000040,0,0x300810a8,0x80000040,
+0x1024000,0x300810a8,0xf8000400,0x18400,0x3008111d,0xf8000400,0x18400,0x300811a0,0xf8000400,0x18400,0x30081217,0x80000000,0,0x3008129b,0x80000000,0,
+0x3008129b,0xf8000400,0x18400,0x3008129b,0xf8002400,0x18400,0x30081400,0x80000000,0x4000000,0x30081600,0x80000000,0,0x30081600,0xf8000400,0x10405,0x30081680,
+0xf8000400,0x28400,0x30081700,0x80000000,0x4000000,0x30081800,0x80000000,0x4000000,0x30081880,0x80000000,0x4000000,0x30081b00,0x80000000,0x4000000,0x30081b80,0x80000000,
+0x4000000,0x30081cae,0x80000000,0x4000000,0x30082813,0xf8000400,0x18401,0x30088300,0x80001000,0,0x30100503,0x80000018,0,0x30100da7,0x80000000,0,
+0x30100e1c,0x80000040,0x1024000,0x30100f8b,0x80000040,0,0x3010111d,0x80000001,0x20000,0x30101180,0x80000040,0,0x30101217,0x80000000,0,0x30101217,
+0x80000040,0,0x30101280,0x80000040,0,0x30101280,0x80000040,0x1024000,0x3010129b,0x80000040,0,0x3010129b,0x80000040,0x1024000,0x3014129b,0x80000018,
+0,0x3020111d,0x80000000,0x8000,0x30240488,0x20000,0x60,0x30240601,0x50020400,0x60,0x302406a2,0x50020400,0x60,0x302406a2,0x50021000,0x60,
+0x302406a2,0x50021400,0x60,0x30240725,0x50021400,0x60,0x30240c21,0x50020400,0x60,0x30240c21,0x50061000,0x60,0x30240c21,0xd0000400,0x18400,0x30240c21,
+0xd0000400,0x18401,0x30240da7,0x50020400,0x60,0x30240da7,0x50021000,0x60,0x3024129b,0x50020400,0x60,0x3024129b,0x50820000,0x2000060,0x30241581,0x20000,
+0x60,0x30242b00,0,0xc820,0x30248381,0x50021000,0x60,0x3030129b,0x80000001,0x20000,0x30301400,0x80000001,0x2000b,0x30308381,0x50021000,0x60,
+0x303a9d11,0x80200000,0,0x303a9d11,0x80200000,2,0x303a9d91,0x80200000,2,0x303a9e00,0x80080000,0,0x303a9e00,0x80100000,0,0x303a9e80,
+0x80000000,0,0x303a9e91,0xf8000c00,0x18002,0x303aa185,0xf8000400,0x18400,0x303aa311,0xf8400c00,0x18000,0x303aa429,0xf8000400,0x18400,0x303aa4a9,0x80000000,
+0,0x30481217,0x80000040,0,0x30481400,0x80000040,0x5024002,0x304aa429,0xf8002400,0x18400,0x304c0e1c,0xd0000000,0x15800,0x304c1217,0xd0000000,0x15800,
+0x304c129b,0xd0000000,0x15800,0x3050111d,0x80000000,0x8000,0x30581217,0x80000000,0,0x30581500,0x80000000,0,0x30600e1c,0x50020400,0x60,0x30600e1c,
+0x50021000,0x60,0x30600e1c,0x50061000,0x60,0x30600e1c,0xd0000400,0x18000,0x30600e1c,0xf8000400,0x18000,0x30600e1c,0xf8000400,0x18001,0x30601217,0x800000,
+0xc820,0x30601217,0x50020400,0x60,0x30601217,0x50021000,0x60,0x30601217,0x50061000,0x60,0x30601217,0x51021000,0x60,0x30601217,0xd0000400,0x18000,
+0x30601217,0xf8000400,0x18000,0x30601217,0xf9000400,0x18000,0x310028e7,0x810000,0,0x3108040e,0xf8000480,0x10402,0x3108040e,0xf8000480,0x28402,0x31082c1e,
+0x80000000,0,0x31082c1e,0xf8000400,0x18400,0x31082c8d,0xf8000400,0x18400,0x31082d09,0xf8000400,0x10400,0x31082d09,0xf8000400,0x28400,0x31082d80,0x80000000,
+0,0x31082e00,0x80000000,0,0x31082e00,0x80000000,1,0x31082e80,0x80000080,5,0x31082e80,0xf8000480,0x10405,0x31082e80,0xf8000480,0x28405,
+0x31242e00,0x800000,0xc820,0x31242e00,0x50020000,0x60,0x31242e00,0x50021000,0x60,0x31242e00,0xd0000000,0,0x31242e00,0xd0001000,0,0x31242e01,
+0x50021000,0x60,0x31243000,0x800000,0xc820,0x313aaf11,0xf8400c00,0x18000,0x313aaf91,0xf8000c00,0x18001,0x314c2e80,0xd0000080,0x15805,0x32041b80,0x80000000,
+0x4000000,0x32049980,0x80000000,0,0x32080219,0xf8000400,0x28400,0x3208040e,0x80000080,0,0x3208040e,0xf8000400,0x10400,0x3208040e,0xf8000400,0x28400,
+0x32080488,0xf8000400,0x10400,0x32080488,0xf8000400,0x28400,0x32080602,0xf8000400,0x18400,0x32080725,0xf8000400,0x18400,0x32080e8c,0xf8000400,0x18400,0x32081400,
+0x800080,0xc820,0x32081400,0x80000000,0x4000000,0x32081400,0x80000000,0x4000002,0x32081400,0x80000080,0x4000000,0x32081499,0xf8000400,0x1040f,0x32081600,0x80000000,
+0,0x32081600,0x80000080,0,0x32081600,0x80000080,5,0x32081600,0xf8000480,0x10405,0x32081600,0xf8000480,0x28405,0x32081700,0x80000080,0x4000000,
+0x32081780,0x80000080,0x4000000,0x32081800,0x80000000,0x4000000,0x32081800,0x80000080,0x4000000,0x32081a80,0x80000000,0x4000000,0x32081b00,0x80000080,0x4000000,0x32081b80,
+0x80000000,0x4000000,0x32082a82,0xf8000400,0x18400,0x32083088,0xf8000400,0x10400,0x32083088,0xf8000400,0x28400,0x3208312a,0xf8000400,0x18400,0x320831ab,0xf8000400,
+0x18400,0x3208322c,0xf8000400,0x18400,0x320832ad,0xf8000400,0x18400,0x32083300,0x80000080,0x4000000,0x32083380,0x80000080,0x4000000,0x32083400,0x80000080,0x4000000,
+0x32083480,0x80000080,0x4000000,0x32083500,0x80000080,0x4000000,0x32083500,0x80000080,0x4000001,0x32083500,0x80000080,0x4000002,0x32101400,0x80000001,0x20002,0x32103180,
+0x80000000,0,0x32201c00,0x80000000,0x4008000,0x32203480,0x80000080,0x4008000,0x3221ab80,0x80000000,0x8011,0x32223300,0x80000080,0x4008000,0x32223480,0x80000080,
+0x4008000,0x32241581,0x20000,0x60,0x32241581,0x50020000,0x60,0x32241581,0x50020080,0x60,0x3224312a,0x50020400,0x60,0x3224312a,0x50060000,0x60,
+0x322431ab,0x50020400,0x60,0x322431ab,0x50060000,0x60,0x3224322c,0x50020400,0x60,0x322432ad,0x50020400,0x60,0x32248381,0x50020000,0x60,0x3224b601,
+0x50820000,0x2000060,0x32308381,0x50820000,0x60,0x323a9e80,0x80000000,0,0x323a9f14,0xf8000400,0x18010,0x323a9f96,0xf8000400,0x18c10,0x323aa200,0x80000000,
+3,0x323aa4a9,0x80000000,0,0x323aa791,0xf8000400,0x18401,0x323aa980,0x80000000,0x4000000,0x32481400,0x80000040,0x5024002,0x324a9e80,0xf8000400,0x18400,
+0x324a9e91,0xf8000400,0x18400,0x324a9f14,0xf8000400,0x18000,0x324a9f80,0x80000008,0xc00,0x324ab596,0xf8000400,0x18c00,0x32501c00,0x80000000,0x4008000,0x32503480,
+0x80000080,0x4008000,0x3251ab80,0x80000000,0x8011,0x32523300,0x80000080,0x4008000,0x32523480,0x80000080,0x4008000,0x32542882,0x80000000,8,0x32581500,0x80000000,
+0,0x32781400,0x800000,0xc820,0x40049b80,0x80000000,0x4000000,0x40080219,0xf8000400,0x10400,0x40080299,0xf8000400,0x10400,0x40080300,0x80001000,0,
+0x4008040e,0xf8000400,0x10400,0x4008040e,0xf8000400,0x28400,0x4008040e,0xf8000400,0x28402,0x40080600,0x800000,0xc820,0x40080602,0x80000000,0,0x40080602,
+0xf8000400,0x18400,0x400806a2,0xf8000400,0x18400,0x4008078a,0xf8000400,0x18400,0x40080804,0xf8000400,0x18400,0x4008090f,0xf8000400,0x18400,0x4008099f,0xf8000400,
+0x18400,0x40080a23,0x80000000,0,0x40080b15,0xf8000400,0x18400,0x40081217,0x80000000,0,0x40081400,0x80000008,0x4000000,0x40081400,0xd0000000,0x1c00,
+0x40081600,0x80000000,2,0x40081800,0x80000000,0x4000000,0x40081800,0x80000080,0x4000000,0x40081b80,0x80000000,0x4000000,0x40082880,0x80000000,0,0x40082d09,
+0xf8000400,0x10400,0x40082d09,0xf8000400,0x28400,0x40082e80,0xf8000480,0x10405,0x400837b0,0x80000000,0,0x400837b0,0xf8000400,0x18400,0x40083897,0x80000000,
+0,0x40083908,0xf8000400,0x10400,0x4008390e,0xf8000400,0x10400,0x4008390e,0xf8001400,0x1040e,0x4008390e,0xf8001400,0x1040f,0x40083919,0xf8000400,0x10400,
+0x40083919,0xf8001400,0x10400,0x40083919,0xf8001400,0x1040e,0x40083919,0xf8001400,0x1040f,0x40083980,0x80000000,0x4000000,0x40083a00,0x80000000,0,0x40083ab1,
+0xf8000400,0x18400,0x40083b31,0xf8000400,0x18400,0x40083b80,0x80000000,0,0x40083c35,0xf8000400,0x18400,0x40083cb3,0xf8000400,0x18400,0x40083d32,0xf8000400,
+0x18400,0x40083daf,0xf8000400,0x18400,0x40083e00,0x80000000,0,0x40089980,0x80000000,0,0x40103b80,0x80000000,0,0x40103c35,0x80000040,0,
+0x4022a980,0x80000000,0x8010,0x40240602,0x50020400,0x60,0x40240602,0x50021000,0x60,0x40240602,0x50021400,0x60,0x40240890,0x50020400,0x60,0x40240890,
+0xd0000400,0x18400,0x4024090f,0x50020400,0x60,0x40240b15,0x50021000,0x60,0x402437b0,0x50020400,0x60,0x402437b0,0x50021000,0x60,0x402437b0,0xd0000400,
+0x18400,0x40248381,0x50021000,0x60,0x4024be81,0x50820000,0x2000060,0x402c37b0,0x80000040,0x1024000,0x40308381,0x50021000,0x60,0x403aa200,0x80000000,0xd,
+0x403aa212,0x80000000,2,0x403aa212,0x80000000,3,0x403aa280,0x80000000,0xd,0x40400602,0x80000000,0x1400,0x404c37b0,0xd0000000,0x15800,0x404c3d32,
+0xd0000000,0x15800,0x4052a980,0x80000000,0x8010,0x4058090f,0x80000000,0,0x40580a23,0x80000000,0,0x40601217,0x50021000,0x60,0x40603834,0xf8000400,
+0x18000,0x41080219,0xf8000400,0x10400,0x41080219,0xf8000400,0x28400,0x4108040e,0xf8000400,0x10400,0x4108040e,0xf8000400,0x28400,0x41080488,0xf8000400,0x10400,
+0x41080488,0xf8000400,0x28400,0x4108078a,0xf8000400,0x18400,0x41080804,0xf8000400,0x18400,0x41080a23,0xf8000400,0x18400,0x41080e8c,0xf8000400,0x18400,0x41080e8c,
+0xf8000400,0x1840f,0x41080f8b,0x80000000,0,0x41080f8b,0xf8000400,0x18400,0x41081400,0x80000000,0x4000000,0x41081499,0xf8000400,0x1040e,0x41081600,0x80000000,
+0,0x41081600,0xf8000480,0x10405,0x41081800,0x80000000,0x4000000,0x41081b80,0x80000000,0x4000000,0x41082e80,0xf8000480,0x10405,0x41083300,0x80000080,0x4000000,
+0x41083908,0xf8000400,0x1040f,0x41083919,0xf8000400,0x10400,0x41083980,0x80000000,0x4000000,0x41083f0e,0x80000000,0,0x41083f8e,0x80000000,0,0x41083f8e,
+0xf8000400,0x18400,0x41084002,0xf8000400,0x18400,0x410840b7,0x80000000,0,0x410840b7,0xf8000400,0x18400,0x41084207,0x80000000,0,0x41084207,0xf8000400,
+0x10400,0x41084207,0xf8000400,0x28400,0x4108428b,0xf8000400,0x18400,0x4108430b,0x80000000,0,0x4108430b,0xf8000400,0x18400,0x4108438c,0xf8000400,0x10400,
+0x41084438,0xf8000400,0x10400,0x41084438,0xf8000400,0x28400,0x410844b9,0x80000000,0,0x410844b9,0xf8000400,0x18400,0x41084500,0x80000000,0,0x4108463d,
+0xf8000400,0x18400,0x4108468e,0xf8000400,0x1040f,0x41084699,0xf8000400,0x10400,0x41084699,0xf8000400,0x1040f,0x41084700,0x80000000,0x4000000,0x410847ba,0x80000000,
+0,0x410847ba,0xf8000400,0x18400,0x4108483c,0xf8000400,0x18400,0x4108483c,0xf8000400,0x1840f,0x41101400,0x80000000,0x4000000,0x411040b7,0x80000000,0,
+0x41104207,0x80000000,0,0x411044b9,0x80000000,0,0x4110463d,0x80000040,0,0x41104700,0x80000000,0x4000000,0x41104700,0x80000018,0x4000000,0x41140da7,
+0x80000000,0,0x41203300,0x80000080,0x4008000,0x4122c880,0x80000000,0x10,0x4122c880,0x80000000,0x8010,0x41240593,0x50020000,0x60,0x41240593,0x50020400,
+0x60,0x41240602,0x50020400,0x60,0x41240f8b,0x50020400,0x60,0x41241581,0x50020000,0x60,0x41243f0e,0x50020000,0x60,0x412440b7,0x50020400,0x60,
+0x412440b7,0xd0000400,0x18400,0x41244181,0x50020000,0x60,0x412444b9,0x50020000,0x60,0x412444b9,0x50020400,0x60,0x412444b9,0x50060000,0x60,0x412447ba,
+0x50020000,0x60,0x412447ba,0x50020400,0x60,0x412447ba,0x50060000,0x60,0x412447ba,0xd0000000,0,0x412447ba,0xd0000400,0x18400,0x41248381,0x50020000,
+0x60,0x412c0593,0x80000000,0,0x412c0602,0x80000000,0,0x412ec880,0x80000000,0x10,0x41308381,0x50020000,0x60,0x413aa200,0x80000000,3,
+0x413aa391,0xf8400c00,0x18000,0x413aa791,0xf8000c00,0x18001,0x413ac100,0x80000000,0,0x413ec880,0x80000000,0x10,0x4142c880,0x80000000,0x1410,0x414c0a23,
+0xd0000000,0x15800,0x414c45bb,0xd0000000,0x15800,0x41503300,0x80000080,0x4008000,0x4152c880,0x80000000,0x8010,0x41540602,0x80000000,0,0x41581500,0x80000000,
+0,0x415c4700,0x80000000,0x4008000,0x416045bb,0x80000000,0,0x416045bb,0xd0000400,0x18000,0x416045bb,0xf8000400,0x18000,0x50080219,0xf8000400,0x10400,
+0x50080219,0xf8000400,0x28400,0x5008040e,0xf8000400,0x10400,0x50080488,0xf8000400,0x10400,0x50080488,0xf8000400,0x28400,0x5008078a,0xf8000400,0x18400,0x50080b15,
+0x80000000,0,0x50081600,0x80000000,0,0x50081619,0xf8000400,0x10400,0x50081699,0xf8000400,0x10400,0x50081800,0x80000000,0x4000000,0x50081800,0x80000080,
+0x4000000,0x50081b80,0x80000000,0x4000000,0x50082e80,0xf8000480,0x10405,0x50082e80,0xf8000480,0x28405,0x50083088,0xf8000400,0x10400,0x50083088,0xf8000400,0x28400,
+0x50083300,0x80000080,0x4000000,0x50083980,0x80000000,0x4000000,0x50084500,0xf8001400,0x18400,0x50084957,0x80000000,0,0x50084957,0xf8000400,0x18400,0x50084957,
+0xf8001400,0x18400,0x50084957,0xf8002400,0x18400,0x500849be,0x80000000,0,0x500849be,0xf8000400,0x18400,0x500849be,0xf8000400,0x18401,0x50084a19,0xf8000400,
+0x10400,0x50084a19,0xf8000400,0x28400,0x50084a80,0x80001000,0,0x50084b5a,0xf8000400,0x18400,0x50084bdb,0x80000000,0,0x50084bdb,0xf8000400,0x18400,
+0x50084c65,0xf8000400,0x18400,0x50084ce5,0xf8000400,0x18400,0x50084d00,0x80000000,0,0x501049be,0x80000000,0,0x501049be,0x80000040,0,0x501049be,
+0x80000040,0x1024000,0x50104bdb,0x80000040,0,0x50104ce5,0x80000040,0,0x50144b5a,0x80000000,0,0x50240593,0x50021400,0x60,0x50240b15,0x50020400,
+0x60,0x50241581,0x50020080,0x60,0x50244181,0x50021000,0x60,0x50244957,0x50021000,0x60,0x502449be,0x50020400,0x60,0x502449be,0x50021000,0x60,
+0x502449be,0xd0000400,0x18400,0x502449be,0xd0000400,0x18401,0x502449be,0xd0041000,0,0x502c4957,0x80000040,0x1024000,0x502c4b5a,0x80000040,0x1024000,0x50404957,
+0x80000040,0x1400,0x504c4957,0xd0000000,0x15800,0x504c49be,0xd0000000,0x15800};
+
+static const int32_t countPropsVectors=3384;
+static const int32_t propsVectorsColumns=3;
+static const int32_t indexes[UPROPS_INDEX_COUNT]={0x1a54,0x1a54,0x1a54,0x1a54,0x3b66,3,0x489e,0,0,0,0x8ecd73,0x29d31,0,0,0,0};
+
diff --git a/Build/source/libs/icu/icu-xetex/common/uchriter.cpp b/Build/source/libs/icu/icu-xetex/common/uchriter.cpp
new file mode 100644
index 00000000000..ae73695a810
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/uchriter.cpp
@@ -0,0 +1,363 @@
+/*
+******************************************************************************
+* Copyright (C) 1998-2004, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+******************************************************************************
+*/
+
+#include "unicode/uchriter.h"
+#include "unicode/ustring.h"
+#include "uhash.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UCharCharacterIterator)
+
+UCharCharacterIterator::UCharCharacterIterator()
+ : CharacterIterator(),
+ text(0)
+{
+ // never default construct!
+}
+
+UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+ int32_t length)
+ : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0),
+ text(textPtr)
+{
+}
+
+UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+ int32_t length,
+ int32_t position)
+ : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, position),
+ text(textPtr)
+{
+}
+
+UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+ int32_t length,
+ int32_t textBegin,
+ int32_t textEnd,
+ int32_t position)
+ : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, textBegin, textEnd, position),
+ text(textPtr)
+{
+}
+
+UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator& that)
+: CharacterIterator(that),
+ text(that.text)
+{
+}
+
+UCharCharacterIterator&
+UCharCharacterIterator::operator=(const UCharCharacterIterator& that) {
+ CharacterIterator::operator=(that);
+ text = that.text;
+ return *this;
+}
+
+UCharCharacterIterator::~UCharCharacterIterator() {
+}
+
+UBool
+UCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+
+ if (getDynamicClassID() != that.getDynamicClassID()) {
+ return FALSE;
+ }
+
+ UCharCharacterIterator& realThat = (UCharCharacterIterator&)that;
+
+ return text == realThat.text
+ && textLength == realThat.textLength
+ && pos == realThat.pos
+ && begin == realThat.begin
+ && end == realThat.end;
+}
+
+int32_t
+UCharCharacterIterator::hashCode() const {
+ return uhash_hashUCharsN(text, textLength) ^ pos ^ begin ^ end;
+}
+
+CharacterIterator*
+UCharCharacterIterator::clone() const {
+ return new UCharCharacterIterator(*this);
+}
+
+UChar
+UCharCharacterIterator::first() {
+ pos = begin;
+ if(pos < end) {
+ return text[pos];
+ } else {
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::firstPostInc() {
+ pos = begin;
+ if(pos < end) {
+ return text[pos++];
+ } else {
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::last() {
+ pos = end;
+ if(pos > begin) {
+ return text[--pos];
+ } else {
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::setIndex(int32_t position) {
+ if(position < begin) {
+ pos = begin;
+ } else if(position > end) {
+ pos = end;
+ } else {
+ pos = position;
+ }
+ if(pos < end) {
+ return text[pos];
+ } else {
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::current() const {
+ if (pos >= begin && pos < end) {
+ return text[pos];
+ } else {
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::next() {
+ if (pos + 1 < end) {
+ return text[++pos];
+ } else {
+ /* make current() return DONE */
+ pos = end;
+ return DONE;
+ }
+}
+
+UChar
+UCharCharacterIterator::nextPostInc() {
+ if (pos < end) {
+ return text[pos++];
+ } else {
+ return DONE;
+ }
+}
+
+UBool
+UCharCharacterIterator::hasNext() {
+ return (UBool)(pos < end ? TRUE : FALSE);
+}
+
+UChar
+UCharCharacterIterator::previous() {
+ if (pos > begin) {
+ return text[--pos];
+ } else {
+ return DONE;
+ }
+}
+
+UBool
+UCharCharacterIterator::hasPrevious() {
+ return (UBool)(pos > begin ? TRUE : FALSE);
+}
+
+UChar32
+UCharCharacterIterator::first32() {
+ pos = begin;
+ if(pos < end) {
+ int32_t i = pos;
+ UChar32 c;
+ UTF_NEXT_CHAR(text, i, end, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::first32PostInc() {
+ pos = begin;
+ if(pos < end) {
+ UChar32 c;
+ UTF_NEXT_CHAR(text, pos, end, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::last32() {
+ pos = end;
+ if(pos > begin) {
+ UChar32 c;
+ UTF_PREV_CHAR(text, begin, pos, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::setIndex32(int32_t position) {
+ if(position < begin) {
+ position = begin;
+ } else if(position > end) {
+ position = end;
+ }
+ if(position < end) {
+ UTF_SET_CHAR_START(text, begin, position);
+ int32_t i = this->pos = position;
+ UChar32 c;
+ UTF_NEXT_CHAR(text, i, end, c);
+ return c;
+ } else {
+ this->pos = position;
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::current32() const {
+ if (pos >= begin && pos < end) {
+ UChar32 c;
+ UTF_GET_CHAR(text, begin, pos, end, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::next32() {
+ if (pos < end) {
+ UTF_FWD_1(text, pos, end);
+ if(pos < end) {
+ int32_t i = pos;
+ UChar32 c;
+ UTF_NEXT_CHAR(text, i, end, c);
+ return c;
+ }
+ }
+ /* make current() return DONE */
+ pos = end;
+ return DONE;
+}
+
+UChar32
+UCharCharacterIterator::next32PostInc() {
+ if (pos < end) {
+ UChar32 c;
+ UTF_NEXT_CHAR(text, pos, end, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+UChar32
+UCharCharacterIterator::previous32() {
+ if (pos > begin) {
+ UChar32 c;
+ UTF_PREV_CHAR(text, begin, pos, c);
+ return c;
+ } else {
+ return DONE;
+ }
+}
+
+int32_t
+UCharCharacterIterator::move(int32_t delta, CharacterIterator::EOrigin origin) {
+ switch(origin) {
+ case kStart:
+ pos = begin + delta;
+ break;
+ case kCurrent:
+ pos += delta;
+ break;
+ case kEnd:
+ pos = end + delta;
+ break;
+ default:
+ break;
+ }
+
+ if(pos < begin) {
+ pos = begin;
+ } else if(pos > end) {
+ pos = end;
+ }
+
+ return pos;
+}
+
+int32_t
+UCharCharacterIterator::move32(int32_t delta, CharacterIterator::EOrigin origin) {
+ // this implementation relies on the "safe" version of the UTF macros
+ // (or the trustworthiness of the caller)
+ switch(origin) {
+ case kStart:
+ pos = begin;
+ if(delta > 0) {
+ UTF_FWD_N(text, pos, end, delta);
+ }
+ break;
+ case kCurrent:
+ if(delta > 0) {
+ UTF_FWD_N(text, pos, end, delta);
+ } else {
+ UTF_BACK_N(text, begin, pos, -delta);
+ }
+ break;
+ case kEnd:
+ pos = end;
+ if(delta < 0) {
+ UTF_BACK_N(text, begin, pos, -delta);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return pos;
+}
+
+void UCharCharacterIterator::setText(const UChar* newText,
+ int32_t newTextLength) {
+ text = newText;
+ if(newText == 0 || newTextLength < 0) {
+ newTextLength = 0;
+ }
+ end = textLength = newTextLength;
+ pos = begin = 0;
+}
+
+void
+UCharCharacterIterator::getText(UnicodeString& result) {
+ result = UnicodeString(text, textLength);
+}
+
+U_NAMESPACE_END
diff --git a/Build/source/libs/icu/icu-xetex/common/ucln.h b/Build/source/libs/icu/icu-xetex/common/ucln.h
new file mode 100644
index 00000000000..a4573e93bb2
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucln.h
@@ -0,0 +1,68 @@
+/*
+******************************************************************************
+* *
+* Copyright (C) 2001-2007, International Business Machines *
+* Corporation and others. All Rights Reserved. *
+* *
+******************************************************************************
+* file name: ucln_cmn.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001July05
+* created by: George Rhoten
+*/
+
+#ifndef __UCLN_H__
+#define __UCLN_H__
+
+#include "unicode/utypes.h"
+
+/** These are the functions used to register a library's memory cleanup
+ * functions. Each library should define a single library register function
+ * to call this API. In the i18n library, it is ucln_i18n_registerCleanup().
+ *
+ * None of the cleanup functions should use a mutex to clean up an API's
+ * allocated memory because a cleanup function is not meant to be thread safe,
+ * and plenty of data cannot be reference counted in order to make sure that
+ * no one else needs the allocated data.
+ *
+ * In order to make a cleanup function get called when u_cleanup is called,
+ * You should add your function to the library specific cleanup function.
+ * If the cleanup function is not in the common library, the code that
+ * allocates the memory should call the library specific cleanup function.
+ * For instance, in the i18n library, any memory allocated statically must
+ * call ucln_i18n_registerCleanup() from the ucln_in.h header. These library
+ * cleanup functions are needed in order to prevent a circular dependency
+ * between the common library and any other library.
+ *
+ * The order of the cleanup is very important. In general, an API that
+ * depends on a second API should be cleaned up before the second API.
+ * For instance, the default converter in ustring depends upon the converter
+ * API. So the default converter should be closed before the converter API
+ * has its cache flushed. This will prevent any memory leaks due to
+ * reference counting.
+ *
+ * Please see common/ucln_cmn.{h,c} and i18n/ucln_in.{h,c} for examples.
+ */
+
+typedef enum ECleanupLibraryType {
+ UCLN_START = -1,
+ UCLN_CUSTOM, /* Custom is for anyone else. */
+ UCLN_CTESTFW,
+ UCLN_LAYOUTEX,
+ UCLN_LAYOUT,
+ UCLN_IO,
+ UCLN_I18N,
+ UCLN_COMMON /* This must be the last one to cleanup. */
+} ECleanupLibraryType;
+
+U_CDECL_BEGIN
+typedef UBool U_CALLCONV cleanupFunc(void);
+U_CDECL_END
+
+U_CAPI void U_EXPORT2 ucln_registerCleanup(ECleanupLibraryType type,
+ cleanupFunc *func);
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucln_cmn.c b/Build/source/libs/icu/icu-xetex/common/ucln_cmn.c
new file mode 100644
index 00000000000..452e628bb38
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucln_cmn.c
@@ -0,0 +1,74 @@
+/*
+******************************************************************************
+* *
+* Copyright (C) 2001-2006, International Business Machines *
+* Corporation and others. All Rights Reserved. *
+* *
+******************************************************************************
+* file name: ucln_cmn.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001July05
+* created by: George Rhoten
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uclean.h"
+#include "utracimp.h"
+#include "ustr_imp.h"
+#include "unormimp.h"
+#include "ucln_cmn.h"
+#include "umutex.h"
+#include "ucln.h"
+#include "cmemory.h"
+#include "uassert.h"
+
+static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT];
+static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
+
+U_CFUNC void
+ucln_common_registerCleanup(ECleanupCommonType type,
+ cleanupFunc *func)
+{
+ U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT);
+ if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT)
+ {
+ gCommonCleanupFunctions[type] = func;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucln_registerCleanup(ECleanupLibraryType type,
+ cleanupFunc *func)
+{
+ U_ASSERT(UCLN_START < type && type < UCLN_COMMON);
+ if (UCLN_START < type && type < UCLN_COMMON)
+ {
+ gLibCleanupFunctions[type] = func;
+ }
+}
+
+U_CFUNC UBool ucln_lib_cleanup(void) {
+ ECleanupLibraryType libType = UCLN_START;
+ ECleanupCommonType commonFunc = UCLN_COMMON_START;
+
+ for (libType++; libType
+#endif
+
+U_CFUNC uint16_t
+udata_getHeaderSize(const DataHeader *udh) {
+ if(udh==NULL) {
+ return 0;
+ } else if(udh->info.isBigEndian==U_IS_BIG_ENDIAN) {
+ /* same endianness */
+ return udh->dataHeader.headerSize;
+ } else {
+ /* opposite endianness */
+ uint16_t x=udh->dataHeader.headerSize;
+ return (uint16_t)((x<<8)|(x>>8));
+ }
+}
+
+U_CFUNC uint16_t
+udata_getInfoSize(const UDataInfo *info) {
+ if(info==NULL) {
+ return 0;
+ } else if(info->isBigEndian==U_IS_BIG_ENDIAN) {
+ /* same endianness */
+ return info->size;
+ } else {
+ /* opposite endianness */
+ uint16_t x=info->size;
+ return (uint16_t)((x<<8)|(x>>8));
+ }
+}
+
+/*-----------------------------------------------------------------------------*
+ * *
+ * Pointer TOCs. TODO: This form of table-of-contents should be removed *
+ * because DLLs must be relocated on loading to correct the *
+ * pointer values and this operation makes shared memory *
+ * mapping of the data much less likely to work. *
+ * *
+ *-----------------------------------------------------------------------------*/
+typedef struct {
+ const char *entryName;
+ const DataHeader *pHeader;
+} PointerTOCEntry;
+
+
+typedef struct {
+ uint32_t count;
+ uint32_t reserved;
+ PointerTOCEntry entry[2]; /* Actual size is from count. */
+} PointerTOC;
+
+
+/* definition of OffsetTOC struct types moved to ucmndata.h */
+
+/*-----------------------------------------------------------------------------*
+ * *
+ * entry point lookup implementations *
+ * *
+ *-----------------------------------------------------------------------------*/
+static uint32_t offsetTOCEntryCount(const UDataMemory *pData) {
+ int32_t retVal=0;
+ const UDataOffsetTOC *toc = (UDataOffsetTOC *)pData->toc;
+ if (toc != NULL) {
+ retVal = toc->count;
+ }
+ return retVal;
+}
+
+
+static const DataHeader *
+offsetTOCLookupFn(const UDataMemory *pData,
+ const char *tocEntryName,
+ int32_t *pLength,
+ UErrorCode *pErrorCode) {
+ const UDataOffsetTOC *toc = (UDataOffsetTOC *)pData->toc;
+ if(toc!=NULL) {
+ const char *base=(const char *)toc;
+ uint32_t start, limit, number, lastNumber;
+ int32_t strResult;
+ const UDataOffsetTOCEntry *entry;
+
+ /* perform a binary search for the data in the common data's table of contents */
+#if defined (UDATA_DEBUG_DUMP)
+ /* list the contents of the TOC each time .. not recommended */
+ for(start=0;startcount;start++) {
+ fprintf(stderr, "\tx%d: %s\n", start, &base[toc->entry[start].nameOffset]);
+ }
+#endif
+
+ start=0;
+ limit=toc->count; /* number of names in this table of contents */
+ lastNumber=limit;
+ entry=toc->entry;
+ for (;;) {
+ number = (start+limit)/2;
+ if (lastNumber == number) { /* Have we moved? */
+ break; /* We haven't moved, and it wasn't found; */
+ /* or the empty stub common data library was used during build. */
+ }
+ lastNumber = number;
+ strResult = uprv_strcmp(tocEntryName, base+entry[number].nameOffset);
+ if(strResult<0) {
+ limit=number;
+ } else if (strResult>0) {
+ start=number;
+ }
+ else {
+ /* found it */
+#ifdef UDATA_DEBUG
+ fprintf(stderr, "%s: Found.\n", tocEntryName);
+#endif
+ entry += number; /* Alias the entry to the current entry. */
+ if((number+1) < toc->count) {
+ *pLength = (int32_t)(entry[1].dataOffset - entry->dataOffset);
+ } else {
+ *pLength = -1;
+ }
+ return (const DataHeader *)(base+entry->dataOffset);
+ }
+ }
+#ifdef UDATA_DEBUG
+ fprintf(stderr, "%s: Not found.\n", tocEntryName);
+#endif
+ return NULL;
+ } else {
+#ifdef UDATA_DEBUG
+ fprintf(stderr, "returning header\n");
+#endif
+
+ return pData->pHeader;
+ }
+}
+
+
+static uint32_t pointerTOCEntryCount(const UDataMemory *pData) {
+ const PointerTOC *toc = (PointerTOC *)pData->toc;
+ return (uint32_t)((toc != NULL) ? (toc->count) : 0);
+}
+
+
+static const DataHeader *pointerTOCLookupFn(const UDataMemory *pData,
+ const char *name,
+ int32_t *pLength,
+ UErrorCode *pErrorCode) {
+ if(pData->toc!=NULL) {
+ const PointerTOC *toc = (PointerTOC *)pData->toc;
+ uint32_t start, limit, number, lastNumber;
+ int32_t strResult;
+
+#if defined (UDATA_DEBUG_DUMP)
+ /* list the contents of the TOC each time .. not recommended */
+ for(start=0;startcount;start++) {
+ fprintf(stderr, "\tx%d: %s\n", start, toc->entry[start].entryName);
+ }
+#endif
+
+ /* perform a binary search for the data in the common data's table of contents */
+ start=0;
+ limit=toc->count;
+ lastNumber=limit;
+
+ for (;;) {
+ number = (start+limit)/2;
+ if (lastNumber == number) { /* Have we moved? */
+ break; /* We haven't moved, and it wasn't found, */
+ /* or the empty stub common data library was used during build. */
+ }
+ lastNumber = number;
+ strResult = uprv_strcmp(name, toc->entry[number].entryName);
+ if(strResult<0) {
+ limit=number;
+ } else if (strResult>0) {
+ start=number;
+ }
+ else {
+ /* found it */
+#ifdef UDATA_DEBUG
+ fprintf(STDErr, "%s: Found.\n", toc->entry[number].entryName);
+#endif
+ *pLength=-1;
+ return UDataMemory_normalizeDataPointer(toc->entry[number].pHeader);
+ }
+ }
+#ifdef UDATA_DEBUG
+ fprintf(stderr, "%s: Not found.\n", name);
+#endif
+ return NULL;
+ } else {
+ return pData->pHeader;
+ }
+}
+
+static const commonDataFuncs CmnDFuncs = {offsetTOCLookupFn, offsetTOCEntryCount};
+static const commonDataFuncs ToCPFuncs = {pointerTOCLookupFn, pointerTOCEntryCount};
+
+
+
+/*----------------------------------------------------------------------*
+ * *
+ * checkCommonData Validate the format of a common data file. *
+ * Fill in the virtual function ptr based on TOC type *
+ * If the data is invalid, close the UDataMemory *
+ * and set the appropriate error code. *
+ * *
+ *----------------------------------------------------------------------*/
+void udata_checkCommonData(UDataMemory *udm, UErrorCode *err) {
+ if (U_FAILURE(*err)) {
+ return;
+ }
+
+ if(!(udm->pHeader->dataHeader.magic1==0xda &&
+ udm->pHeader->dataHeader.magic2==0x27 &&
+ udm->pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
+ udm->pHeader->info.charsetFamily==U_CHARSET_FAMILY)
+ ) {
+ /* header not valid */
+ *err=U_INVALID_FORMAT_ERROR;
+ }
+ else if (udm->pHeader->info.dataFormat[0]==0x43 &&
+ udm->pHeader->info.dataFormat[1]==0x6d &&
+ udm->pHeader->info.dataFormat[2]==0x6e &&
+ udm->pHeader->info.dataFormat[3]==0x44 &&
+ udm->pHeader->info.formatVersion[0]==1
+ ) {
+ /* dataFormat="CmnD" */
+ udm->vFuncs = &CmnDFuncs;
+ udm->toc=(const char *)udm->pHeader+udata_getHeaderSize(udm->pHeader);
+ }
+ else if(udm->pHeader->info.dataFormat[0]==0x54 &&
+ udm->pHeader->info.dataFormat[1]==0x6f &&
+ udm->pHeader->info.dataFormat[2]==0x43 &&
+ udm->pHeader->info.dataFormat[3]==0x50 &&
+ udm->pHeader->info.formatVersion[0]==1
+ ) {
+ /* dataFormat="ToCP" */
+ udm->vFuncs = &ToCPFuncs;
+ udm->toc=(const char *)udm->pHeader+udata_getHeaderSize(udm->pHeader);
+ }
+ else {
+ /* dataFormat not recognized */
+ *err=U_INVALID_FORMAT_ERROR;
+ }
+
+ if (U_FAILURE(*err)) {
+ /* If the data is no good and we memory-mapped it ourselves,
+ * close the memory mapping so it doesn't leak. Note that this has
+ * no effect on non-memory mapped data, other than clearing fields in udm.
+ */
+ udata_close(udm);
+ }
+}
+
+/*
+ * TODO: Add a udata_swapPackageHeader() function that swaps an ICU .dat package
+ * header but not its sub-items.
+ * This function will be needed for automatic runtime swapping.
+ * Sub-items should not be swapped to limit the swapping to the parts of the
+ * package that are actually used.
+ *
+ * Since lengths of items are implicit in the order and offsets of their
+ * ToC entries, and since offsets are relative to the start of the ToC,
+ * a swapped version may need to generate a different data structure
+ * with pointers to the original data items and with their lengths
+ * (-1 for the last one if it is not known), and maybe even pointers to the
+ * swapped versions of the items.
+ * These pointers to swapped versions would establish a cache;
+ * instead, each open data item could simply own the storage for its swapped
+ * data. This fits better with the current design.
+ *
+ * markus 2003sep18 Jitterbug 2235
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucmndata.h b/Build/source/libs/icu/icu-xetex/common/ucmndata.h
new file mode 100644
index 00000000000..9634ed840f6
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucmndata.h
@@ -0,0 +1,109 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2003, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************/
+
+
+/*----------------------------------------------------------------------------------
+ *
+ * UCommonData An abstract interface for dealing with ICU Common Data Files.
+ * ICU Common Data Files are a grouping of a number of individual
+ * data items (resources, converters, tables, anything) into a
+ * single file or dll. The combined format includes a table of
+ * contents for locating the individual items by name.
+ *
+ * Two formats for the table of contents are supported, which is
+ * why there is an abstract inteface involved.
+ *
+ * These functions are part of the ICU internal implementation, and
+ * are not inteded to be used directly by applications.
+ */
+
+#ifndef __UCMNDATA_H__
+#define __UCMNDATA_H__
+
+#include "unicode/udata.h"
+#include "umapfile.h"
+
+
+#define COMMON_DATA_NAME U_ICUDATA_NAME
+
+typedef struct {
+ uint16_t headerSize;
+ uint8_t magic1;
+ uint8_t magic2;
+} MappedData;
+
+
+typedef struct {
+ MappedData dataHeader;
+ UDataInfo info;
+} DataHeader;
+
+typedef struct {
+ uint32_t nameOffset;
+ uint32_t dataOffset;
+} UDataOffsetTOCEntry;
+
+typedef struct {
+ uint32_t count;
+ UDataOffsetTOCEntry entry[2]; /* Actual size of array is from count. */
+} UDataOffsetTOC;
+
+/**
+ * Get the header size from a const DataHeader *udh.
+ * Handles opposite-endian data.
+ *
+ * @internal
+ */
+U_CFUNC uint16_t
+udata_getHeaderSize(const DataHeader *udh);
+
+/**
+ * Get the UDataInfo.size from a const UDataInfo *info.
+ * Handles opposite-endian data.
+ *
+ * @internal
+ */
+U_CFUNC uint16_t
+udata_getInfoSize(const UDataInfo *info);
+
+/*
+ * "Virtual" functions for data lookup.
+ * To call one, given a UDataMemory *p, the code looks like this:
+ * p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
+ * (I sure do wish this was written in C++, not C)
+ */
+
+typedef const DataHeader *
+(* LookupFn)(const UDataMemory *pData,
+ const char *tocEntryName,
+ int32_t *pLength,
+ UErrorCode *pErrorCode);
+
+typedef uint32_t
+(* NumEntriesFn)(const UDataMemory *pData);
+
+typedef struct {
+ LookupFn Lookup;
+ NumEntriesFn NumEntries;
+} commonDataFuncs;
+
+
+/*
+ * Functions to check whether a UDataMemory refers to memory containing
+ * a recognizable header and table of contents a Common Data Format
+ *
+ * If a valid header and TOC are found,
+ * set the CommonDataFuncs function dispatch vector in the UDataMemory
+ * to point to the right functions for the TOC type.
+ * otherwise
+ * set an errorcode.
+ */
+void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
+
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv.c b/Build/source/libs/icu/icu-xetex/common/ucnv.c
new file mode 100644
index 00000000000..9ef346fb612
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv.c
@@ -0,0 +1,2888 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1998-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* ucnv.c:
+* Implements APIs for the ICU's codeset conversion library;
+* mostly calls through internal functions;
+* created by Bertrand A. Damiba
+*
+* Modification History:
+*
+* Date Name Description
+* 04/04/99 helena Fixed internal header inclusion.
+* 05/09/00 helena Added implementation to handle fallback mappings.
+* 06/20/2000 helena OS/400 port changes; mostly typecast.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ustring.h"
+#include "unicode/ucnv.h"
+#include "unicode/ucnv_err.h"
+#include "unicode/uset.h"
+#include "putilimp.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "utracimp.h"
+#include "ustr_imp.h"
+#include "ucnv_imp.h"
+#include "ucnv_cnv.h"
+#include "ucnv_bld.h"
+
+/* size of intermediate and preflighting buffers in ucnv_convert() */
+#define CHUNK_SIZE 1024
+
+typedef struct UAmbiguousConverter {
+ const char *name;
+ const UChar variant5c;
+} UAmbiguousConverter;
+
+static const UAmbiguousConverter ambiguousConverters[]={
+ { "ibm-897_P100-1995", 0xa5 },
+ { "ibm-942_P120-1999", 0xa5 },
+ { "ibm-943_P130-1999", 0xa5 },
+ { "ibm-946_P100-1995", 0xa5 },
+ { "ibm-33722_P120-1999", 0xa5 },
+ /*{ "ibm-54191_P100-2006", 0xa5 },*/
+ /*{ "ibm-62383_P100-2007", 0xa5 },*/
+ /*{ "ibm-891_P100-1995", 0x20a9 },*/
+ { "ibm-944_P100-1995", 0x20a9 },
+ { "ibm-949_P110-1999", 0x20a9 },
+ { "ibm-1363_P110-1997", 0x20a9 },
+ { "ISO_2022,locale=ko,version=0", 0x20a9 }
+};
+
+/*Calls through createConverter */
+U_CAPI UConverter* U_EXPORT2
+ucnv_open (const char *name,
+ UErrorCode * err)
+{
+ UConverter *r;
+
+ if (err == NULL || U_FAILURE (*err)) {
+ return NULL;
+ }
+
+ r = ucnv_createConverter(NULL, name, err);
+ return r;
+}
+
+U_CAPI UConverter* U_EXPORT2
+ucnv_openPackage (const char *packageName, const char *converterName, UErrorCode * err)
+{
+ return ucnv_createConverterFromPackage(packageName, converterName, err);
+}
+
+/*Extracts the UChar* to a char* and calls through createConverter */
+U_CAPI UConverter* U_EXPORT2
+ucnv_openU (const UChar * name,
+ UErrorCode * err)
+{
+ char asciiName[UCNV_MAX_CONVERTER_NAME_LENGTH];
+
+ if (err == NULL || U_FAILURE(*err))
+ return NULL;
+ if (name == NULL)
+ return ucnv_open (NULL, err);
+ if (u_strlen(name) >= UCNV_MAX_CONVERTER_NAME_LENGTH)
+ {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ return ucnv_open(u_austrcpy(asciiName, name), err);
+}
+
+/* Copy the string that is represented by the UConverterPlatform enum
+ * @param platformString An output buffer
+ * @param platform An enum representing a platform
+ * @return the length of the copied string.
+ */
+static int32_t
+ucnv_copyPlatformString(char *platformString, UConverterPlatform pltfrm)
+{
+ switch (pltfrm)
+ {
+ case UCNV_IBM:
+ uprv_strcpy(platformString, "ibm-");
+ return 4;
+ case UCNV_UNKNOWN:
+ break;
+ }
+
+ /* default to empty string */
+ *platformString = 0;
+ return 0;
+}
+
+/*Assumes a $platform-#codepage.$CONVERTER_FILE_EXTENSION scheme and calls
+ *through createConverter*/
+U_CAPI UConverter* U_EXPORT2
+ucnv_openCCSID (int32_t codepage,
+ UConverterPlatform platform,
+ UErrorCode * err)
+{
+ char myName[UCNV_MAX_CONVERTER_NAME_LENGTH];
+ int32_t myNameLen;
+
+ if (err == NULL || U_FAILURE (*err))
+ return NULL;
+
+ /* ucnv_copyPlatformString could return "ibm-" or "cp" */
+ myNameLen = ucnv_copyPlatformString(myName, platform);
+ T_CString_integerToString(myName + myNameLen, codepage, 10);
+
+ return ucnv_createConverter(NULL, myName, err);
+}
+
+/* Creating a temporary stack-based object that can be used in one thread,
+and created from a converter that is shared across threads.
+*/
+
+U_CAPI UConverter* U_EXPORT2
+ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status)
+{
+ UConverter *localConverter, *allocatedConverter;
+ int32_t bufferSizeNeeded;
+ char *stackBufferChars = (char *)stackBuffer;
+ UErrorCode cbErr;
+ UConverterToUnicodeArgs toUArgs = {
+ sizeof(UConverterToUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ UConverterFromUnicodeArgs fromUArgs = {
+ sizeof(UConverterFromUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_CLONE);
+
+ if (status == NULL || U_FAILURE(*status)){
+ UTRACE_EXIT_STATUS(status? *status: U_ILLEGAL_ARGUMENT_ERROR);
+ return 0;
+ }
+
+ if (!pBufferSize || !cnv){
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ UTRACE_EXIT_STATUS(*status);
+ return 0;
+ }
+
+ UTRACE_DATA3(UTRACE_OPEN_CLOSE, "clone converter %s at %p into stackBuffer %p",
+ ucnv_getName(cnv, status), cnv, stackBuffer);
+
+ if (cnv->sharedData->impl->safeClone != NULL) {
+ /* call the custom safeClone function for sizing */
+ bufferSizeNeeded = 0;
+ cnv->sharedData->impl->safeClone(cnv, NULL, &bufferSizeNeeded, status);
+ }
+ else
+ {
+ /* inherent sizing */
+ bufferSizeNeeded = sizeof(UConverter);
+ }
+
+ if (*pBufferSize <= 0){ /* 'preflighting' request - set needed size into *pBufferSize */
+ *pBufferSize = bufferSizeNeeded;
+ UTRACE_EXIT_VALUE(bufferSizeNeeded);
+ return 0;
+ }
+
+
+ /* Pointers on 64-bit platforms need to be aligned
+ * on a 64-bit boundary in memory.
+ */
+ if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
+ int32_t offsetUp = (int32_t)U_ALIGNMENT_OFFSET_UP(stackBufferChars);
+ if(*pBufferSize > offsetUp) {
+ *pBufferSize -= offsetUp;
+ stackBufferChars += offsetUp;
+ } else {
+ /* prevent using the stack buffer but keep the size > 0 so that we do not just preflight */
+ *pBufferSize = 1;
+ }
+ }
+
+ stackBuffer = (void *)stackBufferChars;
+
+ /* Now, see if we must allocate any memory */
+ if (*pBufferSize < bufferSizeNeeded || stackBuffer == NULL)
+ {
+ /* allocate one here...*/
+ localConverter = allocatedConverter = (UConverter *) uprv_malloc (bufferSizeNeeded);
+
+ if(localConverter == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ UTRACE_EXIT_STATUS(*status);
+ return NULL;
+ }
+
+ if (U_SUCCESS(*status)) {
+ *status = U_SAFECLONE_ALLOCATED_WARNING;
+ }
+
+ /* record the fact that memory was allocated */
+ *pBufferSize = bufferSizeNeeded;
+ } else {
+ /* just use the stack buffer */
+ localConverter = (UConverter*) stackBuffer;
+ allocatedConverter = NULL;
+ }
+
+ uprv_memset(localConverter, 0, bufferSizeNeeded);
+
+ /* Copy initial state */
+ uprv_memcpy(localConverter, cnv, sizeof(UConverter));
+ localConverter->isCopyLocal = localConverter->isExtraLocal = FALSE;
+
+ /* copy the substitution string */
+ if (cnv->subChars == (uint8_t *)cnv->subUChars) {
+ localConverter->subChars = (uint8_t *)localConverter->subUChars;
+ } else {
+ localConverter->subChars = (uint8_t *)uprv_malloc(UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR);
+ if (localConverter->subChars == NULL) {
+ uprv_free(allocatedConverter);
+ UTRACE_EXIT_STATUS(*status);
+ return NULL;
+ }
+ uprv_memcpy(localConverter->subChars, cnv->subChars, UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR);
+ }
+
+ /* now either call the safeclone fcn or not */
+ if (cnv->sharedData->impl->safeClone != NULL) {
+ /* call the custom safeClone function */
+ localConverter = cnv->sharedData->impl->safeClone(cnv, localConverter, pBufferSize, status);
+ }
+
+ if(localConverter==NULL || U_FAILURE(*status)) {
+ if (allocatedConverter != NULL && allocatedConverter->subChars != (uint8_t *)allocatedConverter->subUChars) {
+ uprv_free(allocatedConverter->subChars);
+ }
+ uprv_free(allocatedConverter);
+ UTRACE_EXIT_STATUS(*status);
+ return NULL;
+ }
+
+ /* increment refcount of shared data if needed */
+ /*
+ Checking whether it's an algorithic converter is okay
+ in multithreaded applications because the value never changes.
+ Don't check referenceCounter for any other value.
+ */
+ if (cnv->sharedData->referenceCounter != ~0) {
+ ucnv_incrementRefCount(cnv->sharedData);
+ }
+
+ if(localConverter == (UConverter*)stackBuffer) {
+ /* we're using user provided data - set to not destroy */
+ localConverter->isCopyLocal = TRUE;
+ }
+
+ /* allow callback functions to handle any memory allocation */
+ toUArgs.converter = fromUArgs.converter = localConverter;
+ cbErr = U_ZERO_ERROR;
+ cnv->fromCharErrorBehaviour(cnv->toUContext, &toUArgs, NULL, 0, UCNV_CLONE, &cbErr);
+ cbErr = U_ZERO_ERROR;
+ cnv->fromUCharErrorBehaviour(cnv->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLONE, &cbErr);
+
+ UTRACE_EXIT_PTR_STATUS(localConverter, *status);
+ return localConverter;
+}
+
+
+
+/*Decreases the reference counter in the shared immutable section of the object
+ *and frees the mutable part*/
+
+U_CAPI void U_EXPORT2
+ucnv_close (UConverter * converter)
+{
+ UErrorCode errorCode = U_ZERO_ERROR;
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_CLOSE);
+
+ if (converter == NULL)
+ {
+ UTRACE_EXIT();
+ return;
+ }
+
+ UTRACE_DATA3(UTRACE_OPEN_CLOSE, "close converter %s at %p, isCopyLocal=%b",
+ ucnv_getName(converter, &errorCode), converter, converter->isCopyLocal);
+
+ /* In order to speed up the close, only call the callbacks when they have been changed.
+ This performance check will only work when the callbacks are set within a shared library
+ or from user code that statically links this code. */
+ /* first, notify the callback functions that the converter is closed */
+ if (converter->fromCharErrorBehaviour != UCNV_TO_U_DEFAULT_CALLBACK) {
+ UConverterToUnicodeArgs toUArgs = {
+ sizeof(UConverterToUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+
+ toUArgs.converter = converter;
+ errorCode = U_ZERO_ERROR;
+ converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_CLOSE, &errorCode);
+ }
+ if (converter->fromUCharErrorBehaviour != UCNV_FROM_U_DEFAULT_CALLBACK) {
+ UConverterFromUnicodeArgs fromUArgs = {
+ sizeof(UConverterFromUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ fromUArgs.converter = converter;
+ errorCode = U_ZERO_ERROR;
+ converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLOSE, &errorCode);
+ }
+
+ if (converter->sharedData->impl->close != NULL) {
+ converter->sharedData->impl->close(converter);
+ }
+
+ if (converter->subChars != (uint8_t *)converter->subUChars) {
+ uprv_free(converter->subChars);
+ }
+
+ /*
+ Checking whether it's an algorithic converter is okay
+ in multithreaded applications because the value never changes.
+ Don't check referenceCounter for any other value.
+ */
+ if (converter->sharedData->referenceCounter != ~0) {
+ ucnv_unloadSharedDataIfReady(converter->sharedData);
+ }
+
+ if(!converter->isCopyLocal){
+ uprv_free(converter);
+ }
+
+ UTRACE_EXIT();
+}
+
+/*returns a single Name from the list, will return NULL if out of bounds
+ */
+U_CAPI const char* U_EXPORT2
+ucnv_getAvailableName (int32_t n)
+{
+ if (0 <= n && n <= 0xffff) {
+ UErrorCode err = U_ZERO_ERROR;
+ const char *name = ucnv_bld_getAvailableConverter((uint16_t)n, &err);
+ if (U_SUCCESS(err)) {
+ return name;
+ }
+ }
+ return NULL;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_countAvailable ()
+{
+ UErrorCode err = U_ZERO_ERROR;
+ return ucnv_bld_countAvailableConverters(&err);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_getSubstChars (const UConverter * converter,
+ char *mySubChar,
+ int8_t * len,
+ UErrorCode * err)
+{
+ if (U_FAILURE (*err))
+ return;
+
+ if (converter->subCharLen <= 0) {
+ /* Unicode string or empty string from ucnv_setSubstString(). */
+ *len = 0;
+ return;
+ }
+
+ if (*len < converter->subCharLen) /*not enough space in subChars */
+ {
+ *err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return;
+ }
+
+ uprv_memcpy (mySubChar, converter->subChars, converter->subCharLen); /*fills in the subchars */
+ *len = converter->subCharLen; /*store # of bytes copied to buffer */
+}
+
+U_CAPI void U_EXPORT2
+ucnv_setSubstChars (UConverter * converter,
+ const char *mySubChar,
+ int8_t len,
+ UErrorCode * err)
+{
+ if (U_FAILURE (*err))
+ return;
+
+ /*Makes sure that the subChar is within the codepages char length boundaries */
+ if ((len > converter->sharedData->staticData->maxBytesPerChar)
+ || (len < converter->sharedData->staticData->minBytesPerChar))
+ {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ uprv_memcpy (converter->subChars, mySubChar, len); /*copies the subchars */
+ converter->subCharLen = len; /*sets the new len */
+
+ /*
+ * There is currently (2001Feb) no separate API to set/get subChar1.
+ * In order to always have subChar written after it is explicitly set,
+ * we set subChar1 to 0.
+ */
+ converter->subChar1 = 0;
+
+ return;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_setSubstString(UConverter *cnv,
+ const UChar *s,
+ int32_t length,
+ UErrorCode *err) {
+ UAlignedMemory cloneBuffer[U_CNV_SAFECLONE_BUFFERSIZE / sizeof(UAlignedMemory) + 1];
+ char chars[UCNV_ERROR_BUFFER_LENGTH];
+
+ UConverter *clone;
+ uint8_t *subChars;
+ int32_t cloneSize, length8;
+
+ /* Let the following functions check all arguments. */
+ cloneSize = sizeof(cloneBuffer);
+ clone = ucnv_safeClone(cnv, cloneBuffer, &cloneSize, err);
+ ucnv_setFromUCallBack(clone, UCNV_FROM_U_CALLBACK_STOP, NULL, NULL, NULL, err);
+ length8 = ucnv_fromUChars(clone, chars, (int32_t)sizeof(chars), s, length, err);
+ ucnv_close(clone);
+ if (U_FAILURE(*err)) {
+ return;
+ }
+
+ if (cnv->sharedData->impl->writeSub == NULL
+#if !UCONFIG_NO_LEGACY_CONVERSION
+ || (cnv->sharedData->staticData->conversionType == UCNV_MBCS &&
+ ucnv_MBCSGetType(cnv) != UCNV_EBCDIC_STATEFUL)
+#endif
+ ) {
+ /* The converter is not stateful. Store the charset bytes as a fixed string. */
+ subChars = (uint8_t *)chars;
+ } else {
+ /*
+ * The converter has a non-default writeSub() function, indicating
+ * that it is stateful.
+ * Store the Unicode string for on-the-fly conversion for correct
+ * state handling.
+ */
+ if (length > UCNV_ERROR_BUFFER_LENGTH) {
+ /*
+ * Should not occur. The converter should output at least one byte
+ * per UChar, which means that ucnv_fromUChars() should catch all
+ * overflows.
+ */
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+ subChars = (uint8_t *)s;
+ if (length < 0) {
+ length = u_strlen(s);
+ }
+ length8 = length * U_SIZEOF_UCHAR;
+ }
+
+ /*
+ * For storing the substitution string, select either the small buffer inside
+ * UConverter or allocate a subChars buffer.
+ */
+ if (length8 > UCNV_MAX_SUBCHAR_LEN) {
+ /* Use a separate buffer for the string. Outside UConverter to not make it too large. */
+ if (cnv->subChars == (uint8_t *)cnv->subUChars) {
+ /* Allocate a new buffer for the string. */
+ cnv->subChars = (uint8_t *)uprv_malloc(UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR);
+ if (cnv->subChars == NULL) {
+ cnv->subChars = (uint8_t *)cnv->subUChars;
+ *err = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ uprv_memset(cnv->subChars, 0, UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR);
+ }
+ }
+
+ /* Copy the substitution string into the UConverter or its subChars buffer. */
+ if (length8 == 0) {
+ cnv->subCharLen = 0;
+ } else {
+ uprv_memcpy(cnv->subChars, subChars, length8);
+ if (subChars == (uint8_t *)chars) {
+ cnv->subCharLen = (int8_t)length8;
+ } else /* subChars == s */ {
+ cnv->subCharLen = (int8_t)-length;
+ }
+ }
+
+ /* See comment in ucnv_setSubstChars(). */
+ cnv->subChar1 = 0;
+}
+
+/*resets the internal states of a converter
+ *goal : have the same behaviour than a freshly created converter
+ */
+static void _reset(UConverter *converter, UConverterResetChoice choice,
+ UBool callCallback) {
+ if(converter == NULL) {
+ return;
+ }
+
+ if(callCallback) {
+ /* first, notify the callback functions that the converter is reset */
+ UConverterToUnicodeArgs toUArgs = {
+ sizeof(UConverterToUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ UConverterFromUnicodeArgs fromUArgs = {
+ sizeof(UConverterFromUnicodeArgs),
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ UErrorCode errorCode;
+
+ toUArgs.converter = fromUArgs.converter = converter;
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ errorCode = U_ZERO_ERROR;
+ converter->fromCharErrorBehaviour(converter->toUContext, &toUArgs, NULL, 0, UCNV_RESET, &errorCode);
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ errorCode = U_ZERO_ERROR;
+ converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_RESET, &errorCode);
+ }
+ }
+
+ /* now reset the converter itself */
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ converter->toUnicodeStatus = converter->sharedData->toUnicodeStatus;
+ converter->mode = 0;
+ converter->toULength = 0;
+ converter->invalidCharLength = converter->UCharErrorBufferLength = 0;
+ converter->preToULength = 0;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ converter->fromUnicodeStatus = 0;
+ converter->fromUChar32 = 0;
+ converter->invalidUCharLength = converter->charErrorBufferLength = 0;
+ converter->preFromUFirstCP = U_SENTINEL;
+ converter->preFromULength = 0;
+ }
+
+ if (converter->sharedData->impl->reset != NULL) {
+ /* call the custom reset function */
+ converter->sharedData->impl->reset(converter, choice);
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucnv_reset(UConverter *converter)
+{
+ _reset(converter, UCNV_RESET_BOTH, TRUE);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_resetToUnicode(UConverter *converter)
+{
+ _reset(converter, UCNV_RESET_TO_UNICODE, TRUE);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_resetFromUnicode(UConverter *converter)
+{
+ _reset(converter, UCNV_RESET_FROM_UNICODE, TRUE);
+}
+
+U_CAPI int8_t U_EXPORT2
+ucnv_getMaxCharSize (const UConverter * converter)
+{
+ return converter->maxBytesPerUChar;
+}
+
+
+U_CAPI int8_t U_EXPORT2
+ucnv_getMinCharSize (const UConverter * converter)
+{
+ return converter->sharedData->staticData->minBytesPerChar;
+}
+
+U_CAPI const char* U_EXPORT2
+ucnv_getName (const UConverter * converter, UErrorCode * err)
+
+{
+ if (U_FAILURE (*err))
+ return NULL;
+ if(converter->sharedData->impl->getName){
+ const char* temp= converter->sharedData->impl->getName(converter);
+ if(temp)
+ return temp;
+ }
+ return converter->sharedData->staticData->name;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_getCCSID(const UConverter * converter,
+ UErrorCode * err)
+{
+ int32_t ccsid;
+ if (U_FAILURE (*err))
+ return -1;
+
+ ccsid = converter->sharedData->staticData->codepage;
+ if (ccsid == 0) {
+ /* Rare case. This is for cases like gb18030,
+ which doesn't have an IBM cannonical name, but does have an IBM alias. */
+ const char *standardName = ucnv_getStandardName(ucnv_getName(converter, err), "IBM", err);
+ if (U_SUCCESS(*err) && standardName) {
+ const char *ccsidStr = uprv_strchr(standardName, '-');
+ if (ccsidStr) {
+ ccsid = (int32_t)atol(ccsidStr+1); /* +1 to skip '-' */
+ }
+ }
+ }
+ return ccsid;
+}
+
+
+U_CAPI UConverterPlatform U_EXPORT2
+ucnv_getPlatform (const UConverter * converter,
+ UErrorCode * err)
+{
+ if (U_FAILURE (*err))
+ return UCNV_UNKNOWN;
+
+ return (UConverterPlatform)converter->sharedData->staticData->platform;
+}
+
+U_CAPI void U_EXPORT2
+ ucnv_getToUCallBack (const UConverter * converter,
+ UConverterToUCallback *action,
+ const void **context)
+{
+ *action = converter->fromCharErrorBehaviour;
+ *context = converter->toUContext;
+}
+
+U_CAPI void U_EXPORT2
+ ucnv_getFromUCallBack (const UConverter * converter,
+ UConverterFromUCallback *action,
+ const void **context)
+{
+ *action = converter->fromUCharErrorBehaviour;
+ *context = converter->fromUContext;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_setToUCallBack (UConverter * converter,
+ UConverterToUCallback newAction,
+ const void* newContext,
+ UConverterToUCallback *oldAction,
+ const void** oldContext,
+ UErrorCode * err)
+{
+ if (U_FAILURE (*err))
+ return;
+ if (oldAction) *oldAction = converter->fromCharErrorBehaviour;
+ converter->fromCharErrorBehaviour = newAction;
+ if (oldContext) *oldContext = converter->toUContext;
+ converter->toUContext = newContext;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_setFromUCallBack (UConverter * converter,
+ UConverterFromUCallback newAction,
+ const void* newContext,
+ UConverterFromUCallback *oldAction,
+ const void** oldContext,
+ UErrorCode * err)
+{
+ if (U_FAILURE (*err))
+ return;
+ if (oldAction) *oldAction = converter->fromUCharErrorBehaviour;
+ converter->fromUCharErrorBehaviour = newAction;
+ if (oldContext) *oldContext = converter->fromUContext;
+ converter->fromUContext = newContext;
+}
+
+static void
+_updateOffsets(int32_t *offsets, int32_t length,
+ int32_t sourceIndex, int32_t errorInputLength) {
+ int32_t *limit;
+ int32_t delta, offset;
+
+ if(sourceIndex>=0) {
+ /*
+ * adjust each offset by adding the previous sourceIndex
+ * minus the length of the input sequence that caused an
+ * error, if any
+ */
+ delta=sourceIndex-errorInputLength;
+ } else {
+ /*
+ * set each offset to -1 because this conversion function
+ * does not handle offsets
+ */
+ delta=-1;
+ }
+
+ limit=offsets+length;
+ if(delta==0) {
+ /* most common case, nothing to do */
+ } else if(delta>0) {
+ /* add the delta to each offset (but not if the offset is <0) */
+ while(offsets=0) {
+ *offsets=offset+delta;
+ }
+ ++offsets;
+ }
+ } else /* delta<0 */ {
+ /*
+ * set each offset to -1 because this conversion function
+ * does not handle offsets
+ * or the error input sequence started in a previous buffer
+ */
+ while(offsetsconverter;
+ s=pArgs->source;
+ t=pArgs->target;
+ offsets=pArgs->offsets;
+
+ /* get the converter implementation function */
+ sourceIndex=0;
+ if(offsets==NULL) {
+ fromUnicode=cnv->sharedData->impl->fromUnicode;
+ } else {
+ fromUnicode=cnv->sharedData->impl->fromUnicodeWithOffsets;
+ if(fromUnicode==NULL) {
+ /* there is no WithOffsets implementation */
+ fromUnicode=cnv->sharedData->impl->fromUnicode;
+ /* we will write -1 for each offset */
+ sourceIndex=-1;
+ }
+ }
+
+ if(cnv->preFromULength>=0) {
+ /* normal mode */
+ realSource=NULL;
+
+ /* avoid compiler warnings - not otherwise necessary, and the values do not matter */
+ realSourceLimit=NULL;
+ realFlush=FALSE;
+ realSourceIndex=0;
+ } else {
+ /*
+ * Previous m:n conversion stored source units from a partial match
+ * and failed to consume all of them.
+ * We need to "replay" them from a temporary buffer and convert them first.
+ */
+ realSource=pArgs->source;
+ realSourceLimit=pArgs->sourceLimit;
+ realFlush=pArgs->flush;
+ realSourceIndex=sourceIndex;
+
+ uprv_memcpy(replay, cnv->preFromU, -cnv->preFromULength*U_SIZEOF_UCHAR);
+ pArgs->source=replay;
+ pArgs->sourceLimit=replay-cnv->preFromULength;
+ pArgs->flush=FALSE;
+ sourceIndex=-1;
+
+ cnv->preFromULength=0;
+ }
+
+ /*
+ * loop for conversion and error handling
+ *
+ * loop {
+ * convert
+ * loop {
+ * update offsets
+ * handle end of input
+ * handle errors/call callback
+ * }
+ * }
+ */
+ for(;;) {
+ if(U_SUCCESS(*err)) {
+ /* convert */
+ fromUnicode(pArgs, err);
+
+ /*
+ * set a flag for whether the converter
+ * successfully processed the end of the input
+ *
+ * need not check cnv->preFromULength==0 because a replay (<0) will cause
+ * sflush && pArgs->source==pArgs->sourceLimit &&
+ cnv->fromUChar32==0);
+ } else {
+ /* handle error from ucnv_convertEx() */
+ converterSawEndOfInput=FALSE;
+ }
+
+ /* no callback called yet for this iteration */
+ calledCallback=FALSE;
+
+ /* no sourceIndex adjustment for conversion, only for callback output */
+ errorInputLength=0;
+
+ /*
+ * loop for offsets and error handling
+ *
+ * iterates at most 3 times:
+ * 1. to clean up after the conversion function
+ * 2. after the callback
+ * 3. after the callback again if there was truncated input
+ */
+ for(;;) {
+ /* update offsets if we write any */
+ if(offsets!=NULL) {
+ int32_t length=(int32_t)(pArgs->target-t);
+ if(length>0) {
+ _updateOffsets(offsets, length, sourceIndex, errorInputLength);
+
+ /*
+ * if a converter handles offsets and updates the offsets
+ * pointer at the end, then pArgs->offset should not change
+ * here;
+ * however, some converters do not handle offsets at all
+ * (sourceIndex<0) or may not update the offsets pointer
+ */
+ pArgs->offsets=offsets+=length;
+ }
+
+ if(sourceIndex>=0) {
+ sourceIndex+=(int32_t)(pArgs->source-s);
+ }
+ }
+
+ if(cnv->preFromULength<0) {
+ /*
+ * switch the source to new replay units (cannot occur while replaying)
+ * after offset handling and before end-of-input and callback handling
+ */
+ if(realSource==NULL) {
+ realSource=pArgs->source;
+ realSourceLimit=pArgs->sourceLimit;
+ realFlush=pArgs->flush;
+ realSourceIndex=sourceIndex;
+
+ uprv_memcpy(replay, cnv->preFromU, -cnv->preFromULength*U_SIZEOF_UCHAR);
+ pArgs->source=replay;
+ pArgs->sourceLimit=replay-cnv->preFromULength;
+ pArgs->flush=FALSE;
+ if((sourceIndex+=cnv->preFromULength)<0) {
+ sourceIndex=-1;
+ }
+
+ cnv->preFromULength=0;
+ } else {
+ /* see implementation note before _fromUnicodeWithCallback() */
+ U_ASSERT(realSource==NULL);
+ *err=U_INTERNAL_PROGRAM_ERROR;
+ }
+ }
+
+ /* update pointers */
+ s=pArgs->source;
+ t=pArgs->target;
+
+ if(U_SUCCESS(*err)) {
+ if(ssourceLimit) {
+ /*
+ * continue with the conversion loop while there is still input left
+ * (continue converting by breaking out of only the inner loop)
+ */
+ break;
+ } else if(realSource!=NULL) {
+ /* switch back from replaying to the real source and continue */
+ pArgs->source=realSource;
+ pArgs->sourceLimit=realSourceLimit;
+ pArgs->flush=realFlush;
+ sourceIndex=realSourceIndex;
+
+ realSource=NULL;
+ break;
+ } else if(pArgs->flush && cnv->fromUChar32!=0) {
+ /*
+ * the entire input stream is consumed
+ * and there is a partial, truncated input sequence left
+ */
+
+ /* inject an error and continue with callback handling */
+ *err=U_TRUNCATED_CHAR_FOUND;
+ calledCallback=FALSE; /* new error condition */
+ } else {
+ /* input consumed */
+ if(pArgs->flush) {
+ /*
+ * return to the conversion loop once more if the flush
+ * flag is set and the conversion function has not
+ * successfully processed the end of the input yet
+ *
+ * (continue converting by breaking out of only the inner loop)
+ */
+ if(!converterSawEndOfInput) {
+ break;
+ }
+
+ /* reset the converter without calling the callback function */
+ _reset(cnv, UCNV_RESET_FROM_UNICODE, FALSE);
+ }
+
+ /* done successfully */
+ return;
+ }
+ }
+
+ /* U_FAILURE(*err) */
+ {
+ UErrorCode e;
+
+ if( calledCallback ||
+ (e=*err)==U_BUFFER_OVERFLOW_ERROR ||
+ (e!=U_INVALID_CHAR_FOUND &&
+ e!=U_ILLEGAL_CHAR_FOUND &&
+ e!=U_TRUNCATED_CHAR_FOUND)
+ ) {
+ /*
+ * the callback did not or cannot resolve the error:
+ * set output pointers and return
+ *
+ * the check for buffer overflow is redundant but it is
+ * a high-runner case and hopefully documents the intent
+ * well
+ *
+ * if we were replaying, then the replay buffer must be
+ * copied back into the UConverter
+ * and the real arguments must be restored
+ */
+ if(realSource!=NULL) {
+ int32_t length;
+
+ U_ASSERT(cnv->preFromULength==0);
+
+ length=(int32_t)(pArgs->sourceLimit-pArgs->source);
+ if(length>0) {
+ uprv_memcpy(cnv->preFromU, pArgs->source, length*U_SIZEOF_UCHAR);
+ cnv->preFromULength=(int8_t)-length;
+ }
+
+ pArgs->source=realSource;
+ pArgs->sourceLimit=realSourceLimit;
+ pArgs->flush=realFlush;
+ }
+
+ return;
+ }
+ }
+
+ /* callback handling */
+ {
+ UChar32 codePoint;
+
+ /* get and write the code point */
+ codePoint=cnv->fromUChar32;
+ errorInputLength=0;
+ U16_APPEND_UNSAFE(cnv->invalidUCharBuffer, errorInputLength, codePoint);
+ cnv->invalidUCharLength=(int8_t)errorInputLength;
+
+ /* set the converter state to deal with the next character */
+ cnv->fromUChar32=0;
+
+ /* call the callback function */
+ cnv->fromUCharErrorBehaviour(cnv->fromUContext, pArgs,
+ cnv->invalidUCharBuffer, errorInputLength, codePoint,
+ *err==U_INVALID_CHAR_FOUND ? UCNV_UNASSIGNED : UCNV_ILLEGAL,
+ err);
+ }
+
+ /*
+ * loop back to the offset handling
+ *
+ * this flag will indicate after offset handling
+ * that a callback was called;
+ * if the callback did not resolve the error, then we return
+ */
+ calledCallback=TRUE;
+ }
+ }
+}
+
+/*
+ * Output the fromUnicode overflow buffer.
+ * Call this function if(cnv->charErrorBufferLength>0).
+ * @return TRUE if overflow
+ */
+static UBool
+ucnv_outputOverflowFromUnicode(UConverter *cnv,
+ char **target, const char *targetLimit,
+ int32_t **pOffsets,
+ UErrorCode *err) {
+ int32_t *offsets;
+ char *overflow, *t;
+ int32_t i, length;
+
+ t=*target;
+ if(pOffsets!=NULL) {
+ offsets=*pOffsets;
+ } else {
+ offsets=NULL;
+ }
+
+ overflow=(char *)cnv->charErrorBuffer;
+ length=cnv->charErrorBufferLength;
+ i=0;
+ while(icharErrorBufferLength=(int8_t)j;
+ *target=t;
+ if(offsets!=NULL) {
+ *pOffsets=offsets;
+ }
+ *err=U_BUFFER_OVERFLOW_ERROR;
+ return TRUE;
+ }
+
+ /* copy the overflow contents to the target */
+ *t++=overflow[i++];
+ if(offsets!=NULL) {
+ *offsets++=-1; /* no source index available for old output */
+ }
+ }
+
+ /* the overflow buffer is completely copied to the target */
+ cnv->charErrorBufferLength=0;
+ *target=t;
+ if(offsets!=NULL) {
+ *pOffsets=offsets;
+ }
+ return FALSE;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_fromUnicode(UConverter *cnv,
+ char **target, const char *targetLimit,
+ const UChar **source, const UChar *sourceLimit,
+ int32_t *offsets,
+ UBool flush,
+ UErrorCode *err) {
+ UConverterFromUnicodeArgs args;
+ const UChar *s;
+ char *t;
+
+ /* check parameters */
+ if(err==NULL || U_FAILURE(*err)) {
+ return;
+ }
+
+ if(cnv==NULL || target==NULL || source==NULL) {
+ *err=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ s=*source;
+ t=*target;
+
+ if ((const void *)U_MAX_PTR(sourceLimit) == (const void *)sourceLimit) {
+ /*
+ Prevent code from going into an infinite loop in case we do hit this
+ limit. The limit pointer is expected to be on a UChar * boundary.
+ This also prevents the next argument check from failing.
+ */
+ sourceLimit = (const UChar *)(((const char *)sourceLimit) - 1);
+ }
+
+ /*
+ * All these conditions should never happen.
+ *
+ * 1) Make sure that the limits are >= to the address source or target
+ *
+ * 2) Make sure that the buffer sizes do not exceed the number range for
+ * int32_t because some functions use the size (in units or bytes)
+ * rather than comparing pointers, and because offsets are int32_t values.
+ *
+ * size_t is guaranteed to be unsigned and large enough for the job.
+ *
+ * Return with an error instead of adjusting the limits because we would
+ * not be able to maintain the semantics that either the source must be
+ * consumed or the target filled (unless an error occurs).
+ * An adjustment would be targetLimit=t+0x7fffffff; for example.
+ *
+ * 3) Make sure that the user didn't incorrectly cast a UChar * pointer
+ * to a char * pointer and provide an incomplete UChar code unit.
+ */
+ if (sourceLimit(size_t)0x3fffffff && sourceLimit>s) ||
+ ((size_t)(targetLimit-t)>(size_t)0x7fffffff && targetLimit>t) ||
+ (((const char *)sourceLimit-(const char *)s) & 1) != 0)
+ {
+ *err=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ /* output the target overflow buffer */
+ if( cnv->charErrorBufferLength>0 &&
+ ucnv_outputOverflowFromUnicode(cnv, target, targetLimit, &offsets, err)
+ ) {
+ /* U_BUFFER_OVERFLOW_ERROR */
+ return;
+ }
+ /* *target may have moved, therefore stop using t */
+
+ if(!flush && s==sourceLimit && cnv->preFromULength>=0) {
+ /* the overflow buffer is emptied and there is no new input: we are done */
+ return;
+ }
+
+ /*
+ * Do not simply return with a buffer overflow error if
+ * !flush && t==targetLimit
+ * because it is possible that the source will not generate any output.
+ * For example, the skip callback may be called;
+ * it does not output anything.
+ */
+
+ /* prepare the converter arguments */
+ args.converter=cnv;
+ args.flush=flush;
+ args.offsets=offsets;
+ args.source=s;
+ args.sourceLimit=sourceLimit;
+ args.target=*target;
+ args.targetLimit=targetLimit;
+ args.size=sizeof(args);
+
+ _fromUnicodeWithCallback(&args, err);
+
+ *source=args.source;
+ *target=args.target;
+}
+
+/* ucnv_toUnicode() --------------------------------------------------------- */
+
+static void
+_toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
+ UConverterToUnicode toUnicode;
+ UConverter *cnv;
+ const char *s;
+ UChar *t;
+ int32_t *offsets;
+ int32_t sourceIndex;
+ int32_t errorInputLength;
+ UBool converterSawEndOfInput, calledCallback;
+
+ /* variables for m:n conversion */
+ char replay[UCNV_EXT_MAX_BYTES];
+ const char *realSource, *realSourceLimit;
+ int32_t realSourceIndex;
+ UBool realFlush;
+
+ cnv=pArgs->converter;
+ s=pArgs->source;
+ t=pArgs->target;
+ offsets=pArgs->offsets;
+
+ /* get the converter implementation function */
+ sourceIndex=0;
+ if(offsets==NULL) {
+ toUnicode=cnv->sharedData->impl->toUnicode;
+ } else {
+ toUnicode=cnv->sharedData->impl->toUnicodeWithOffsets;
+ if(toUnicode==NULL) {
+ /* there is no WithOffsets implementation */
+ toUnicode=cnv->sharedData->impl->toUnicode;
+ /* we will write -1 for each offset */
+ sourceIndex=-1;
+ }
+ }
+
+ if(cnv->preToULength>=0) {
+ /* normal mode */
+ realSource=NULL;
+
+ /* avoid compiler warnings - not otherwise necessary, and the values do not matter */
+ realSourceLimit=NULL;
+ realFlush=FALSE;
+ realSourceIndex=0;
+ } else {
+ /*
+ * Previous m:n conversion stored source units from a partial match
+ * and failed to consume all of them.
+ * We need to "replay" them from a temporary buffer and convert them first.
+ */
+ realSource=pArgs->source;
+ realSourceLimit=pArgs->sourceLimit;
+ realFlush=pArgs->flush;
+ realSourceIndex=sourceIndex;
+
+ uprv_memcpy(replay, cnv->preToU, -cnv->preToULength);
+ pArgs->source=replay;
+ pArgs->sourceLimit=replay-cnv->preToULength;
+ pArgs->flush=FALSE;
+ sourceIndex=-1;
+
+ cnv->preToULength=0;
+ }
+
+ /*
+ * loop for conversion and error handling
+ *
+ * loop {
+ * convert
+ * loop {
+ * update offsets
+ * handle end of input
+ * handle errors/call callback
+ * }
+ * }
+ */
+ for(;;) {
+ if(U_SUCCESS(*err)) {
+ /* convert */
+ toUnicode(pArgs, err);
+
+ /*
+ * set a flag for whether the converter
+ * successfully processed the end of the input
+ *
+ * need not check cnv->preToULength==0 because a replay (<0) will cause
+ * sflush && pArgs->source==pArgs->sourceLimit &&
+ cnv->toULength==0);
+ } else {
+ /* handle error from getNextUChar() or ucnv_convertEx() */
+ converterSawEndOfInput=FALSE;
+ }
+
+ /* no callback called yet for this iteration */
+ calledCallback=FALSE;
+
+ /* no sourceIndex adjustment for conversion, only for callback output */
+ errorInputLength=0;
+
+ /*
+ * loop for offsets and error handling
+ *
+ * iterates at most 3 times:
+ * 1. to clean up after the conversion function
+ * 2. after the callback
+ * 3. after the callback again if there was truncated input
+ */
+ for(;;) {
+ /* update offsets if we write any */
+ if(offsets!=NULL) {
+ int32_t length=(int32_t)(pArgs->target-t);
+ if(length>0) {
+ _updateOffsets(offsets, length, sourceIndex, errorInputLength);
+
+ /*
+ * if a converter handles offsets and updates the offsets
+ * pointer at the end, then pArgs->offset should not change
+ * here;
+ * however, some converters do not handle offsets at all
+ * (sourceIndex<0) or may not update the offsets pointer
+ */
+ pArgs->offsets=offsets+=length;
+ }
+
+ if(sourceIndex>=0) {
+ sourceIndex+=(int32_t)(pArgs->source-s);
+ }
+ }
+
+ if(cnv->preToULength<0) {
+ /*
+ * switch the source to new replay units (cannot occur while replaying)
+ * after offset handling and before end-of-input and callback handling
+ */
+ if(realSource==NULL) {
+ realSource=pArgs->source;
+ realSourceLimit=pArgs->sourceLimit;
+ realFlush=pArgs->flush;
+ realSourceIndex=sourceIndex;
+
+ uprv_memcpy(replay, cnv->preToU, -cnv->preToULength);
+ pArgs->source=replay;
+ pArgs->sourceLimit=replay-cnv->preToULength;
+ pArgs->flush=FALSE;
+ if((sourceIndex+=cnv->preToULength)<0) {
+ sourceIndex=-1;
+ }
+
+ cnv->preToULength=0;
+ } else {
+ /* see implementation note before _fromUnicodeWithCallback() */
+ U_ASSERT(realSource==NULL);
+ *err=U_INTERNAL_PROGRAM_ERROR;
+ }
+ }
+
+ /* update pointers */
+ s=pArgs->source;
+ t=pArgs->target;
+
+ if(U_SUCCESS(*err)) {
+ if(ssourceLimit) {
+ /*
+ * continue with the conversion loop while there is still input left
+ * (continue converting by breaking out of only the inner loop)
+ */
+ break;
+ } else if(realSource!=NULL) {
+ /* switch back from replaying to the real source and continue */
+ pArgs->source=realSource;
+ pArgs->sourceLimit=realSourceLimit;
+ pArgs->flush=realFlush;
+ sourceIndex=realSourceIndex;
+
+ realSource=NULL;
+ break;
+ } else if(pArgs->flush && cnv->toULength>0) {
+ /*
+ * the entire input stream is consumed
+ * and there is a partial, truncated input sequence left
+ */
+
+ /* inject an error and continue with callback handling */
+ *err=U_TRUNCATED_CHAR_FOUND;
+ calledCallback=FALSE; /* new error condition */
+ } else {
+ /* input consumed */
+ if(pArgs->flush) {
+ /*
+ * return to the conversion loop once more if the flush
+ * flag is set and the conversion function has not
+ * successfully processed the end of the input yet
+ *
+ * (continue converting by breaking out of only the inner loop)
+ */
+ if(!converterSawEndOfInput) {
+ break;
+ }
+
+ /* reset the converter without calling the callback function */
+ _reset(cnv, UCNV_RESET_TO_UNICODE, FALSE);
+ }
+
+ /* done successfully */
+ return;
+ }
+ }
+
+ /* U_FAILURE(*err) */
+ {
+ UErrorCode e;
+
+ if( calledCallback ||
+ (e=*err)==U_BUFFER_OVERFLOW_ERROR ||
+ (e!=U_INVALID_CHAR_FOUND &&
+ e!=U_ILLEGAL_CHAR_FOUND &&
+ e!=U_TRUNCATED_CHAR_FOUND &&
+ e!=U_ILLEGAL_ESCAPE_SEQUENCE &&
+ e!=U_UNSUPPORTED_ESCAPE_SEQUENCE)
+ ) {
+ /*
+ * the callback did not or cannot resolve the error:
+ * set output pointers and return
+ *
+ * the check for buffer overflow is redundant but it is
+ * a high-runner case and hopefully documents the intent
+ * well
+ *
+ * if we were replaying, then the replay buffer must be
+ * copied back into the UConverter
+ * and the real arguments must be restored
+ */
+ if(realSource!=NULL) {
+ int32_t length;
+
+ U_ASSERT(cnv->preToULength==0);
+
+ length=(int32_t)(pArgs->sourceLimit-pArgs->source);
+ if(length>0) {
+ uprv_memcpy(cnv->preToU, pArgs->source, length);
+ cnv->preToULength=(int8_t)-length;
+ }
+
+ pArgs->source=realSource;
+ pArgs->sourceLimit=realSourceLimit;
+ pArgs->flush=realFlush;
+ }
+
+ return;
+ }
+ }
+
+ /* copy toUBytes[] to invalidCharBuffer[] */
+ errorInputLength=cnv->invalidCharLength=cnv->toULength;
+ if(errorInputLength>0) {
+ uprv_memcpy(cnv->invalidCharBuffer, cnv->toUBytes, errorInputLength);
+ }
+
+ /* set the converter state to deal with the next character */
+ cnv->toULength=0;
+
+ /* call the callback function */
+ cnv->fromCharErrorBehaviour(cnv->toUContext, pArgs,
+ cnv->invalidCharBuffer, errorInputLength,
+ (*err==U_INVALID_CHAR_FOUND || *err==U_UNSUPPORTED_ESCAPE_SEQUENCE) ?
+ UCNV_UNASSIGNED : UCNV_ILLEGAL,
+ err);
+
+ /*
+ * loop back to the offset handling
+ *
+ * this flag will indicate after offset handling
+ * that a callback was called;
+ * if the callback did not resolve the error, then we return
+ */
+ calledCallback=TRUE;
+ }
+ }
+}
+
+/*
+ * Output the toUnicode overflow buffer.
+ * Call this function if(cnv->UCharErrorBufferLength>0).
+ * @return TRUE if overflow
+ */
+static UBool
+ucnv_outputOverflowToUnicode(UConverter *cnv,
+ UChar **target, const UChar *targetLimit,
+ int32_t **pOffsets,
+ UErrorCode *err) {
+ int32_t *offsets;
+ UChar *overflow, *t;
+ int32_t i, length;
+
+ t=*target;
+ if(pOffsets!=NULL) {
+ offsets=*pOffsets;
+ } else {
+ offsets=NULL;
+ }
+
+ overflow=cnv->UCharErrorBuffer;
+ length=cnv->UCharErrorBufferLength;
+ i=0;
+ while(iUCharErrorBufferLength=(int8_t)j;
+ *target=t;
+ if(offsets!=NULL) {
+ *pOffsets=offsets;
+ }
+ *err=U_BUFFER_OVERFLOW_ERROR;
+ return TRUE;
+ }
+
+ /* copy the overflow contents to the target */
+ *t++=overflow[i++];
+ if(offsets!=NULL) {
+ *offsets++=-1; /* no source index available for old output */
+ }
+ }
+
+ /* the overflow buffer is completely copied to the target */
+ cnv->UCharErrorBufferLength=0;
+ *target=t;
+ if(offsets!=NULL) {
+ *pOffsets=offsets;
+ }
+ return FALSE;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_toUnicode(UConverter *cnv,
+ UChar **target, const UChar *targetLimit,
+ const char **source, const char *sourceLimit,
+ int32_t *offsets,
+ UBool flush,
+ UErrorCode *err) {
+ UConverterToUnicodeArgs args;
+ const char *s;
+ UChar *t;
+
+ /* check parameters */
+ if(err==NULL || U_FAILURE(*err)) {
+ return;
+ }
+
+ if(cnv==NULL || target==NULL || source==NULL) {
+ *err=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ s=*source;
+ t=*target;
+
+ if ((const void *)U_MAX_PTR(targetLimit) == (const void *)targetLimit) {
+ /*
+ Prevent code from going into an infinite loop in case we do hit this
+ limit. The limit pointer is expected to be on a UChar * boundary.
+ This also prevents the next argument check from failing.
+ */
+ targetLimit = (const UChar *)(((const char *)targetLimit) - 1);
+ }
+
+ /*
+ * All these conditions should never happen.
+ *
+ * 1) Make sure that the limits are >= to the address source or target
+ *
+ * 2) Make sure that the buffer sizes do not exceed the number range for
+ * int32_t because some functions use the size (in units or bytes)
+ * rather than comparing pointers, and because offsets are int32_t values.
+ *
+ * size_t is guaranteed to be unsigned and large enough for the job.
+ *
+ * Return with an error instead of adjusting the limits because we would
+ * not be able to maintain the semantics that either the source must be
+ * consumed or the target filled (unless an error occurs).
+ * An adjustment would be sourceLimit=t+0x7fffffff; for example.
+ *
+ * 3) Make sure that the user didn't incorrectly cast a UChar * pointer
+ * to a char * pointer and provide an incomplete UChar code unit.
+ */
+ if (sourceLimit(size_t)0x7fffffff && sourceLimit>s) ||
+ ((size_t)(targetLimit-t)>(size_t)0x3fffffff && targetLimit>t) ||
+ (((const char *)targetLimit-(const char *)t) & 1) != 0
+ ) {
+ *err=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ /* output the target overflow buffer */
+ if( cnv->UCharErrorBufferLength>0 &&
+ ucnv_outputOverflowToUnicode(cnv, target, targetLimit, &offsets, err)
+ ) {
+ /* U_BUFFER_OVERFLOW_ERROR */
+ return;
+ }
+ /* *target may have moved, therefore stop using t */
+
+ if(!flush && s==sourceLimit && cnv->preToULength>=0) {
+ /* the overflow buffer is emptied and there is no new input: we are done */
+ return;
+ }
+
+ /*
+ * Do not simply return with a buffer overflow error if
+ * !flush && t==targetLimit
+ * because it is possible that the source will not generate any output.
+ * For example, the skip callback may be called;
+ * it does not output anything.
+ */
+
+ /* prepare the converter arguments */
+ args.converter=cnv;
+ args.flush=flush;
+ args.offsets=offsets;
+ args.source=s;
+ args.sourceLimit=sourceLimit;
+ args.target=*target;
+ args.targetLimit=targetLimit;
+ args.size=sizeof(args);
+
+ _toUnicodeWithCallback(&args, err);
+
+ *source=args.source;
+ *target=args.target;
+}
+
+/* ucnv_to/fromUChars() ----------------------------------------------------- */
+
+U_CAPI int32_t U_EXPORT2
+ucnv_fromUChars(UConverter *cnv,
+ char *dest, int32_t destCapacity,
+ const UChar *src, int32_t srcLength,
+ UErrorCode *pErrorCode) {
+ const UChar *srcLimit;
+ char *originalDest, *destLimit;
+ int32_t destLength;
+
+ /* check arguments */
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ if( cnv==NULL ||
+ destCapacity<0 || (destCapacity>0 && dest==NULL) ||
+ srcLength<-1 || (srcLength!=0 && src==NULL)
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* initialize */
+ ucnv_resetFromUnicode(cnv);
+ originalDest=dest;
+ if(srcLength==-1) {
+ srcLength=u_strlen(src);
+ }
+ if(srcLength>0) {
+ srcLimit=src+srcLength;
+ destLimit=dest+destCapacity;
+
+ /* pin the destination limit to U_MAX_PTR; NULL check is for OS/400 */
+ if(destLimit0 && dest==NULL) ||
+ srcLength<-1 || (srcLength!=0 && src==NULL))
+ {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* initialize */
+ ucnv_resetToUnicode(cnv);
+ originalDest=dest;
+ if(srcLength==-1) {
+ srcLength=(int32_t)uprv_strlen(src);
+ }
+ if(srcLength>0) {
+ srcLimit=src+srcLength;
+ destLimit=dest+destCapacity;
+
+ /* pin the destination limit to U_MAX_PTR; NULL check is for OS/400 */
+ if(destLimit(size_t)0x7fffffff && sourceLimit>s)) {
+ *err=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0xffff;
+ }
+
+ c=U_SENTINEL;
+
+ /* flush the target overflow buffer */
+ if(cnv->UCharErrorBufferLength>0) {
+ UChar *overflow;
+
+ overflow=cnv->UCharErrorBuffer;
+ i=0;
+ length=cnv->UCharErrorBufferLength;
+ U16_NEXT(overflow, i, length, c);
+
+ /* move the remaining overflow contents up to the beginning */
+ if((cnv->UCharErrorBufferLength=(int8_t)(length-i))>0) {
+ uprv_memmove(cnv->UCharErrorBuffer, cnv->UCharErrorBuffer+i,
+ cnv->UCharErrorBufferLength*U_SIZEOF_UCHAR);
+ }
+
+ if(!U16_IS_LEAD(c) || itoULength==0 && cnv->sharedData->impl->getNextUChar!=NULL) {
+ c=cnv->sharedData->impl->getNextUChar(&args, err);
+ *source=s=args.source;
+ if(*err==U_INDEX_OUTOFBOUNDS_ERROR) {
+ /* reset the converter without calling the callback function */
+ _reset(cnv, UCNV_RESET_TO_UNICODE, FALSE);
+ return 0xffff; /* no output */
+ } else if(U_SUCCESS(*err) && c>=0) {
+ return c;
+ /*
+ * else fall through to use _toUnicode() because
+ * UCNV_GET_NEXT_UCHAR_USE_TO_U: the native function did not want to handle it after all
+ * U_FAILURE: call _toUnicode() for callback handling (do not output c)
+ */
+ }
+ }
+
+ /* convert to one UChar in buffer[0], or handle getNextUChar() errors */
+ _toUnicodeWithCallback(&args, err);
+
+ if(*err==U_BUFFER_OVERFLOW_ERROR) {
+ *err=U_ZERO_ERROR;
+ }
+
+ i=0;
+ length=(int32_t)(args.target-buffer);
+ } else {
+ /* write the lead surrogate from the overflow buffer */
+ buffer[0]=(UChar)c;
+ args.target=buffer+1;
+ i=0;
+ length=1;
+ }
+
+ /* buffer contents starts at i and ends before length */
+
+ if(U_FAILURE(*err)) {
+ c=0xffff; /* no output */
+ } else if(length==0) {
+ /* no input or only state changes */
+ *err=U_INDEX_OUTOFBOUNDS_ERROR;
+ /* no need to reset explicitly because _toUnicodeWithCallback() did it */
+ c=0xffff; /* no output */
+ } else {
+ c=buffer[0];
+ i=1;
+ if(!U16_IS_LEAD(c)) {
+ /* consume c=buffer[0], done */
+ } else {
+ /* got a lead surrogate, see if a trail surrogate follows */
+ UChar c2;
+
+ if(cnv->UCharErrorBufferLength>0) {
+ /* got overflow output from the conversion */
+ if(U16_IS_TRAIL(c2=cnv->UCharErrorBuffer[0])) {
+ /* got a trail surrogate, too */
+ c=U16_GET_SUPPLEMENTARY(c, c2);
+
+ /* move the remaining overflow contents up to the beginning */
+ if((--cnv->UCharErrorBufferLength)>0) {
+ uprv_memmove(cnv->UCharErrorBuffer, cnv->UCharErrorBuffer+1,
+ cnv->UCharErrorBufferLength*U_SIZEOF_UCHAR);
+ }
+ } else {
+ /* c is an unpaired lead surrogate, just return it */
+ }
+ } else if(args.sourceUCharErrorBufferLength)>0) {
+ uprv_memmove(cnv->UCharErrorBuffer+delta, cnv->UCharErrorBuffer,
+ length*U_SIZEOF_UCHAR);
+ }
+ cnv->UCharErrorBufferLength=(int8_t)(length+delta);
+
+ cnv->UCharErrorBuffer[0]=buffer[i++];
+ if(delta>1) {
+ cnv->UCharErrorBuffer[1]=buffer[i];
+ }
+ }
+
+ *source=args.source;
+ return c;
+}
+
+/* ucnv_convert() and siblings ---------------------------------------------- */
+
+U_CAPI void U_EXPORT2
+ucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv,
+ char **target, const char *targetLimit,
+ const char **source, const char *sourceLimit,
+ UChar *pivotStart, UChar **pivotSource,
+ UChar **pivotTarget, const UChar *pivotLimit,
+ UBool reset, UBool flush,
+ UErrorCode *pErrorCode) {
+ UChar pivotBuffer[CHUNK_SIZE];
+ const UChar *myPivotSource;
+ UChar *myPivotTarget;
+ const char *s;
+ char *t;
+
+ UConverterToUnicodeArgs toUArgs;
+ UConverterFromUnicodeArgs fromUArgs;
+ UConverterConvert convert;
+
+ /* error checking */
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ if( targetCnv==NULL || sourceCnv==NULL ||
+ source==NULL || *source==NULL ||
+ target==NULL || *target==NULL || targetLimit==NULL
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ s=*source;
+ t=*target;
+ if((sourceLimit!=NULL && sourceLimit(size_t)0x7fffffff && sourceLimit>s)) ||
+ ((size_t)(targetLimit-t)>(size_t)0x7fffffff && targetLimit>t)
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if(pivotStart==NULL) {
+ if(!flush) {
+ /* streaming conversion requires an explicit pivot buffer */
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ /* use the stack pivot buffer */
+ myPivotSource=myPivotTarget=pivotStart=pivotBuffer;
+ pivotSource=(UChar **)&myPivotSource;
+ pivotTarget=&myPivotTarget;
+ pivotLimit=pivotBuffer+CHUNK_SIZE;
+ } else if( pivotStart>=pivotLimit ||
+ pivotSource==NULL || *pivotSource==NULL ||
+ pivotTarget==NULL || *pivotTarget==NULL ||
+ pivotLimit==NULL
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if(sourceLimit==NULL) {
+ /* get limit of single-byte-NUL-terminated source string */
+ sourceLimit=uprv_strchr(*source, 0);
+ }
+
+ if(reset) {
+ ucnv_resetToUnicode(sourceCnv);
+ ucnv_resetFromUnicode(targetCnv);
+ *pivotSource=*pivotTarget=pivotStart;
+ } else if(targetCnv->charErrorBufferLength>0) {
+ /* output the targetCnv overflow buffer */
+ if(ucnv_outputOverflowFromUnicode(targetCnv, target, targetLimit, NULL, pErrorCode)) {
+ /* U_BUFFER_OVERFLOW_ERROR */
+ return;
+ }
+ /* *target has moved, therefore stop using t */
+
+ if( !flush &&
+ targetCnv->preFromULength>=0 && *pivotSource==*pivotTarget &&
+ sourceCnv->UCharErrorBufferLength==0 && sourceCnv->preToULength>=0 && s==sourceLimit
+ ) {
+ /* the fromUnicode overflow buffer is emptied and there is no new input: we are done */
+ return;
+ }
+ }
+
+ /* Is direct-UTF-8 conversion available? */
+ if( sourceCnv->sharedData->staticData->conversionType==UCNV_UTF8 &&
+ targetCnv->sharedData->impl->fromUTF8!=NULL
+ ) {
+ convert=targetCnv->sharedData->impl->fromUTF8;
+ } else if( targetCnv->sharedData->staticData->conversionType==UCNV_UTF8 &&
+ sourceCnv->sharedData->impl->toUTF8!=NULL
+ ) {
+ convert=sourceCnv->sharedData->impl->toUTF8;
+ } else {
+ convert=NULL;
+ }
+
+ /*
+ * If direct-UTF-8 conversion is available, then we use a smaller
+ * pivot buffer for error handling and partial matches
+ * so that we quickly return to direct conversion.
+ *
+ * 32 is large enough for UCNV_EXT_MAX_UCHARS and UCNV_ERROR_BUFFER_LENGTH.
+ *
+ * We could reduce the pivot buffer size further, at the cost of
+ * buffer overflows from callbacks.
+ * The pivot buffer should not be smaller than the maximum number of
+ * fromUnicode extension table input UChars
+ * (for m:n conversion, see
+ * targetCnv->sharedData->mbcs.extIndexes[UCNV_EXT_COUNT_UCHARS])
+ * or 2 for surrogate pairs.
+ *
+ * Too small a buffer can cause thrashing between pivoting and direct
+ * conversion, with function call overhead outweighing the benefits
+ * of direct conversion.
+ */
+ if(convert!=NULL && (pivotLimit-pivotStart)>32) {
+ pivotLimit=pivotStart+32;
+ }
+
+ /* prepare the converter arguments */
+ fromUArgs.converter=targetCnv;
+ fromUArgs.flush=FALSE;
+ fromUArgs.offsets=NULL;
+ fromUArgs.target=*target;
+ fromUArgs.targetLimit=targetLimit;
+ fromUArgs.size=sizeof(fromUArgs);
+
+ toUArgs.converter=sourceCnv;
+ toUArgs.flush=flush;
+ toUArgs.offsets=NULL;
+ toUArgs.source=s;
+ toUArgs.sourceLimit=sourceLimit;
+ toUArgs.targetLimit=pivotLimit;
+ toUArgs.size=sizeof(toUArgs);
+
+ /*
+ * TODO: Consider separating this function into two functions,
+ * extracting exactly the conversion loop,
+ * for readability and to reduce the set of visible variables.
+ *
+ * Otherwise stop using s and t from here on.
+ */
+ s=t=NULL;
+
+ /*
+ * conversion loop
+ *
+ * The sequence of steps in the loop may appear backward,
+ * but the principle is simple:
+ * In the chain of
+ * source - sourceCnv overflow - pivot - targetCnv overflow - target
+ * empty out later buffers before refilling them from earlier ones.
+ *
+ * The targetCnv overflow buffer is flushed out only once before the loop.
+ */
+ for(;;) {
+ /*
+ * if(pivot not empty or error or replay or flush fromUnicode) {
+ * fromUnicode(pivot -> target);
+ * }
+ *
+ * For pivoting conversion; and for direct conversion for
+ * error callback handling and flushing the replay buffer.
+ */
+ if( *pivotSource<*pivotTarget ||
+ U_FAILURE(*pErrorCode) ||
+ targetCnv->preFromULength<0 ||
+ fromUArgs.flush
+ ) {
+ fromUArgs.source=*pivotSource;
+ fromUArgs.sourceLimit=*pivotTarget;
+ _fromUnicodeWithCallback(&fromUArgs, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ /* target overflow, or conversion error */
+ *pivotSource=(UChar *)fromUArgs.source;
+ break;
+ }
+
+ /*
+ * _fromUnicodeWithCallback() must have consumed the pivot contents
+ * (*pivotSource==*pivotTarget) since it returned with U_SUCCESS()
+ */
+ }
+
+ /* The pivot buffer is empty; reset it so we start at pivotStart. */
+ *pivotSource=*pivotTarget=pivotStart;
+
+ /*
+ * if(sourceCnv overflow buffer not empty) {
+ * move(sourceCnv overflow buffer -> pivot);
+ * continue;
+ * }
+ */
+ /* output the sourceCnv overflow buffer */
+ if(sourceCnv->UCharErrorBufferLength>0) {
+ if(ucnv_outputOverflowToUnicode(sourceCnv, pivotTarget, pivotLimit, NULL, pErrorCode)) {
+ /* U_BUFFER_OVERFLOW_ERROR */
+ *pErrorCode=U_ZERO_ERROR;
+ }
+ continue;
+ }
+
+ /*
+ * check for end of input and break if done
+ *
+ * Checking both flush and fromUArgs.flush ensures that the converters
+ * have been called with the flush flag set if the ucnv_convertEx()
+ * caller set it.
+ */
+ if( toUArgs.source==sourceLimit &&
+ sourceCnv->preToULength>=0 && sourceCnv->toULength==0 &&
+ (!flush || fromUArgs.flush)
+ ) {
+ /* done successfully */
+ break;
+ }
+
+ /*
+ * use direct conversion if available
+ * but not if continuing a partial match
+ * or flushing the toUnicode replay buffer
+ */
+ if(convert!=NULL && targetCnv->preFromUFirstCP<0 && sourceCnv->preToULength==0) {
+ if(*pErrorCode==U_USING_DEFAULT_WARNING) {
+ /* remove a warning that may be set by this function */
+ *pErrorCode=U_ZERO_ERROR;
+ }
+ convert(&fromUArgs, &toUArgs, pErrorCode);
+ if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
+ break;
+ } else if(U_FAILURE(*pErrorCode)) {
+ if(sourceCnv->toULength>0) {
+ /*
+ * Fall through to calling _toUnicodeWithCallback()
+ * for callback handling.
+ *
+ * The pivot buffer will be reset with
+ * *pivotSource=*pivotTarget=pivotStart;
+ * which indicates a toUnicode error to the caller
+ * (*pivotSource==pivotStart shows no pivot UChars consumed).
+ */
+ } else {
+ /*
+ * Indicate a fromUnicode error to the caller
+ * (*pivotSource>pivotStart shows some pivot UChars consumed).
+ */
+ *pivotSource=*pivotTarget=pivotStart+1;
+ /*
+ * Loop around to calling _fromUnicodeWithCallbacks()
+ * for callback handling.
+ */
+ continue;
+ }
+ } else if(*pErrorCode==U_USING_DEFAULT_WARNING) {
+ /*
+ * No error, but the implementation requested to temporarily
+ * fall back to pivoting.
+ */
+ *pErrorCode=U_ZERO_ERROR;
+ /*
+ * The following else branches are almost identical to the end-of-input
+ * handling in _toUnicodeWithCallback().
+ * Avoid calling it just for the end of input.
+ */
+ } else if(flush && sourceCnv->toULength>0) { /* flush==toUArgs.flush */
+ /*
+ * the entire input stream is consumed
+ * and there is a partial, truncated input sequence left
+ */
+
+ /* inject an error and continue with callback handling */
+ *pErrorCode=U_TRUNCATED_CHAR_FOUND;
+ } else {
+ /* input consumed */
+ if(flush) {
+ /* reset the converters without calling the callback functions */
+ _reset(sourceCnv, UCNV_RESET_TO_UNICODE, FALSE);
+ _reset(targetCnv, UCNV_RESET_FROM_UNICODE, FALSE);
+ }
+
+ /* done successfully */
+ break;
+ }
+ }
+
+ /*
+ * toUnicode(source -> pivot);
+ *
+ * For pivoting conversion; and for direct conversion for
+ * error callback handling, continuing partial matches
+ * and flushing the replay buffer.
+ *
+ * The pivot buffer is empty and reset.
+ */
+ toUArgs.target=pivotStart; /* ==*pivotTarget */
+ /* toUArgs.targetLimit=pivotLimit; already set before the loop */
+ _toUnicodeWithCallback(&toUArgs, pErrorCode);
+ *pivotTarget=toUArgs.target;
+ if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
+ /* pivot overflow: continue with the conversion loop */
+ *pErrorCode=U_ZERO_ERROR;
+ } else if(U_FAILURE(*pErrorCode) || (!flush && *pivotTarget==pivotStart)) {
+ /* conversion error, or there was nothing left to convert */
+ break;
+ }
+ /*
+ * else:
+ * _toUnicodeWithCallback() wrote into the pivot buffer,
+ * continue with fromUnicode conversion.
+ *
+ * Set the fromUnicode flush flag if we flush and if toUnicode has
+ * processed the end of the input.
+ */
+ if( flush && toUArgs.source==sourceLimit &&
+ sourceCnv->preToULength>=0 &&
+ sourceCnv->UCharErrorBufferLength==0
+ ) {
+ fromUArgs.flush=TRUE;
+ }
+ }
+
+ /*
+ * The conversion loop is exited when one of the following is true:
+ * - the entire source text has been converted successfully to the target buffer
+ * - a target buffer overflow occurred
+ * - a conversion error occurred
+ */
+
+ *source=toUArgs.source;
+ *target=fromUArgs.target;
+
+ /* terminate the target buffer if possible */
+ if(flush && U_SUCCESS(*pErrorCode)) {
+ if(*target!=targetLimit) {
+ **target=0;
+ if(*pErrorCode==U_STRING_NOT_TERMINATED_WARNING) {
+ *pErrorCode=U_ZERO_ERROR;
+ }
+ } else {
+ *pErrorCode=U_STRING_NOT_TERMINATED_WARNING;
+ }
+ }
+}
+
+/* internal implementation of ucnv_convert() etc. with preflighting */
+static int32_t
+ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter,
+ char *target, int32_t targetCapacity,
+ const char *source, int32_t sourceLength,
+ UErrorCode *pErrorCode) {
+ UChar pivotBuffer[CHUNK_SIZE];
+ UChar *pivot, *pivot2;
+
+ char *myTarget;
+ const char *sourceLimit;
+ const char *targetLimit;
+ int32_t targetLength=0;
+
+ /* set up */
+ if(sourceLength<0) {
+ sourceLimit=uprv_strchr(source, 0);
+ } else {
+ sourceLimit=source+sourceLength;
+ }
+
+ /* if there is no input data, we're done */
+ if(source==sourceLimit) {
+ return u_terminateChars(target, targetCapacity, 0, pErrorCode);
+ }
+
+ pivot=pivot2=pivotBuffer;
+ myTarget=target;
+ targetLength=0;
+
+ if(targetCapacity>0) {
+ /* perform real conversion */
+ targetLimit=target+targetCapacity;
+ ucnv_convertEx(outConverter, inConverter,
+ &myTarget, targetLimit,
+ &source, sourceLimit,
+ pivotBuffer, &pivot, &pivot2, pivotBuffer+CHUNK_SIZE,
+ FALSE,
+ TRUE,
+ pErrorCode);
+ targetLength=(int32_t)(myTarget-target);
+ }
+
+ /*
+ * If the output buffer is exhausted (or we are only "preflighting"), we need to stop writing
+ * to it but continue the conversion in order to store in targetCapacity
+ * the number of bytes that was required.
+ */
+ if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR || targetCapacity==0)
+ {
+ char targetBuffer[CHUNK_SIZE];
+
+ targetLimit=targetBuffer+CHUNK_SIZE;
+ do {
+ *pErrorCode=U_ZERO_ERROR;
+ myTarget=targetBuffer;
+ ucnv_convertEx(outConverter, inConverter,
+ &myTarget, targetLimit,
+ &source, sourceLimit,
+ pivotBuffer, &pivot, &pivot2, pivotBuffer+CHUNK_SIZE,
+ FALSE,
+ TRUE,
+ pErrorCode);
+ targetLength+=(int32_t)(myTarget-targetBuffer);
+ } while(*pErrorCode==U_BUFFER_OVERFLOW_ERROR);
+
+ /* done with preflighting, set warnings and errors as appropriate */
+ return u_terminateChars(target, targetCapacity, targetLength, pErrorCode);
+ }
+
+ /* no need to call u_terminateChars() because ucnv_convertEx() took care of that */
+ return targetLength;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_convert(const char *toConverterName, const char *fromConverterName,
+ char *target, int32_t targetCapacity,
+ const char *source, int32_t sourceLength,
+ UErrorCode *pErrorCode) {
+ UConverter in, out; /* stack-allocated */
+ UConverter *inConverter, *outConverter;
+ int32_t targetLength;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ if( source==NULL || sourceLength<-1 ||
+ targetCapacity<0 || (targetCapacity>0 && target==NULL)
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* if there is no input data, we're done */
+ if(sourceLength==0 || (sourceLength<0 && *source==0)) {
+ return u_terminateChars(target, targetCapacity, 0, pErrorCode);
+ }
+
+ /* create the converters */
+ inConverter=ucnv_createConverter(&in, fromConverterName, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ outConverter=ucnv_createConverter(&out, toConverterName, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ ucnv_close(inConverter);
+ return 0;
+ }
+
+ targetLength=ucnv_internalConvert(outConverter, inConverter,
+ target, targetCapacity,
+ source, sourceLength,
+ pErrorCode);
+
+ ucnv_close(inConverter);
+ ucnv_close(outConverter);
+
+ return targetLength;
+}
+
+/* @internal */
+static int32_t
+ucnv_convertAlgorithmic(UBool convertToAlgorithmic,
+ UConverterType algorithmicType,
+ UConverter *cnv,
+ char *target, int32_t targetCapacity,
+ const char *source, int32_t sourceLength,
+ UErrorCode *pErrorCode) {
+ UConverter algoConverterStatic; /* stack-allocated */
+ UConverter *algoConverter, *to, *from;
+ int32_t targetLength;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ if( cnv==NULL || source==NULL || sourceLength<-1 ||
+ targetCapacity<0 || (targetCapacity>0 && target==NULL)
+ ) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ /* if there is no input data, we're done */
+ if(sourceLength==0 || (sourceLength<0 && *source==0)) {
+ return u_terminateChars(target, targetCapacity, 0, pErrorCode);
+ }
+
+ /* create the algorithmic converter */
+ algoConverter=ucnv_createAlgorithmicConverter(&algoConverterStatic, algorithmicType,
+ "", 0, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* reset the other converter */
+ if(convertToAlgorithmic) {
+ /* cnv->Unicode->algo */
+ ucnv_resetToUnicode(cnv);
+ to=algoConverter;
+ from=cnv;
+ } else {
+ /* algo->Unicode->cnv */
+ ucnv_resetFromUnicode(cnv);
+ from=algoConverter;
+ to=cnv;
+ }
+
+ targetLength=ucnv_internalConvert(to, from,
+ target, targetCapacity,
+ source, sourceLength,
+ pErrorCode);
+
+ ucnv_close(algoConverter);
+
+ return targetLength;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_toAlgorithmic(UConverterType algorithmicType,
+ UConverter *cnv,
+ char *target, int32_t targetCapacity,
+ const char *source, int32_t sourceLength,
+ UErrorCode *pErrorCode) {
+ return ucnv_convertAlgorithmic(TRUE, algorithmicType, cnv,
+ target, targetCapacity,
+ source, sourceLength,
+ pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_fromAlgorithmic(UConverter *cnv,
+ UConverterType algorithmicType,
+ char *target, int32_t targetCapacity,
+ const char *source, int32_t sourceLength,
+ UErrorCode *pErrorCode) {
+ return ucnv_convertAlgorithmic(FALSE, algorithmicType, cnv,
+ target, targetCapacity,
+ source, sourceLength,
+ pErrorCode);
+}
+
+U_CAPI UConverterType U_EXPORT2
+ucnv_getType(const UConverter* converter)
+{
+ int8_t type = converter->sharedData->staticData->conversionType;
+#if !UCONFIG_NO_LEGACY_CONVERSION
+ if(type == UCNV_MBCS) {
+ return ucnv_MBCSGetType(converter);
+ }
+#endif
+ return (UConverterType)type;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_getStarters(const UConverter* converter,
+ UBool starters[256],
+ UErrorCode* err)
+{
+ if (err == NULL || U_FAILURE(*err)) {
+ return;
+ }
+
+ if(converter->sharedData->impl->getStarters != NULL) {
+ converter->sharedData->impl->getStarters(converter, starters, err);
+ } else {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+static const UAmbiguousConverter *ucnv_getAmbiguous(const UConverter *cnv)
+{
+ UErrorCode errorCode;
+ const char *name;
+ int32_t i;
+
+ if(cnv==NULL) {
+ return NULL;
+ }
+
+ errorCode=U_ZERO_ERROR;
+ name=ucnv_getName(cnv, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ return NULL;
+ }
+
+ for(i=0; i<(int32_t)(sizeof(ambiguousConverters)/sizeof(UAmbiguousConverter)); ++i)
+ {
+ if(0==uprv_strcmp(name, ambiguousConverters[i].name))
+ {
+ return ambiguousConverters+i;
+ }
+ }
+
+ return NULL;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_fixFileSeparator(const UConverter *cnv,
+ UChar* source,
+ int32_t sourceLength) {
+ const UAmbiguousConverter *a;
+ int32_t i;
+ UChar variant5c;
+
+ if(cnv==NULL || source==NULL || sourceLength<=0 || (a=ucnv_getAmbiguous(cnv))==NULL)
+ {
+ return;
+ }
+
+ variant5c=a->variant5c;
+ for(i=0; iuseFallback = usesFallback;
+}
+
+U_CAPI UBool U_EXPORT2
+ucnv_usesFallback(const UConverter *cnv)
+{
+ return cnv->useFallback;
+}
+
+U_CAPI void U_EXPORT2
+ucnv_getInvalidChars (const UConverter * converter,
+ char *errBytes,
+ int8_t * len,
+ UErrorCode * err)
+{
+ if (err == NULL || U_FAILURE(*err))
+ {
+ return;
+ }
+ if (len == NULL || errBytes == NULL || converter == NULL)
+ {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (*len < converter->invalidCharLength)
+ {
+ *err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return;
+ }
+ if ((*len = converter->invalidCharLength) > 0)
+ {
+ uprv_memcpy (errBytes, converter->invalidCharBuffer, *len);
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucnv_getInvalidUChars (const UConverter * converter,
+ UChar *errChars,
+ int8_t * len,
+ UErrorCode * err)
+{
+ if (err == NULL || U_FAILURE(*err))
+ {
+ return;
+ }
+ if (len == NULL || errChars == NULL || converter == NULL)
+ {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (*len < converter->invalidUCharLength)
+ {
+ *err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return;
+ }
+ if ((*len = converter->invalidUCharLength) > 0)
+ {
+ uprv_memcpy (errChars, converter->invalidUCharBuffer, sizeof(UChar) * (*len));
+ }
+}
+
+#define SIG_MAX_LEN 5
+
+U_CAPI const char* U_EXPORT2
+ucnv_detectUnicodeSignature( const char* source,
+ int32_t sourceLength,
+ int32_t* signatureLength,
+ UErrorCode* pErrorCode) {
+ int32_t dummy;
+
+ /* initial 0xa5 bytes: make sure that if we read preFromULength > 0){
+ return U16_LENGTH(cnv->preFromUFirstCP)+cnv->preFromULength ;
+ }else if(cnv->preFromULength < 0){
+ return -cnv->preFromULength ;
+ }else if(cnv->fromUChar32 > 0){
+ return 1;
+ }else if(cnv->preFromUFirstCP >0){
+ return U16_LENGTH(cnv->preFromUFirstCP);
+ }
+ return 0;
+
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status){
+
+ if(status == NULL || U_FAILURE(*status)){
+ return -1;
+ }
+ if(cnv == NULL){
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ if(cnv->preToULength > 0){
+ return cnv->preToULength ;
+ }else if(cnv->preToULength < 0){
+ return -cnv->preToULength;
+ }else if(cnv->toULength > 0){
+ return cnv->toULength;
+ }
+ return 0;
+}
+#endif
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv2022.c b/Build/source/libs/icu/icu-xetex/common/ucnv2022.c
new file mode 100644
index 00000000000..dff4ba8340d
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv2022.c
@@ -0,0 +1,3463 @@
+/*
+**********************************************************************
+* Copyright (C) 2000-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: ucnv2022.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2000feb03
+* created by: Markus W. Scherer
+*
+* Change history:
+*
+* 06/29/2000 helena Major rewrite of the callback APIs.
+* 08/08/2000 Ram Included support for ISO-2022-JP-2
+* Changed implementation of toUnicode
+* function
+* 08/21/2000 Ram Added support for ISO-2022-KR
+* 08/29/2000 Ram Seperated implementation of EBCDIC to
+* ucnvebdc.c
+* 09/20/2000 Ram Added support for ISO-2022-CN
+* Added implementations for getNextUChar()
+* for specific 2022 country variants.
+* 10/31/2000 Ram Implemented offsets logic functions
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "unicode/uset.h"
+#include "unicode/ucnv_err.h"
+#include "unicode/ucnv_cb.h"
+#include "ucnv_imp.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+#include "ucnvmbcs.h"
+#include "cstring.h"
+#include "cmemory.h"
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+/*
+ * I am disabling the generic ISO-2022 converter after proposing to do so on
+ * the icu mailing list two days ago.
+ *
+ * Reasons:
+ * 1. It does not fully support the ISO-2022/ECMA-35 specification with all of
+ * its designation sequences, single shifts with return to the previous state,
+ * switch-with-no-return to UTF-16BE or similar, etc.
+ * This is unlike the language-specific variants like ISO-2022-JP which
+ * require a much smaller repertoire of ISO-2022 features.
+ * These variants continue to be supported.
+ * 2. I believe that no one is really using the generic ISO-2022 converter
+ * but rather always one of the language-specific variants.
+ * Note that ICU's generic ISO-2022 converter has always output one escape
+ * sequence followed by UTF-8 for the whole stream.
+ * 3. Switching between subcharsets is extremely slow, because each time
+ * the previous converter is closed and a new one opened,
+ * without any kind of caching, least-recently-used list, etc.
+ * 4. The code is currently buggy, and given the above it does not seem
+ * reasonable to spend the time on maintenance.
+ * 5. ISO-2022 subcharsets should normally be used with 7-bit byte encodings.
+ * This means, for example, that when ISO-8859-7 is designated, the following
+ * ISO-2022 bytes 00..7f should be interpreted as ISO-8859-7 bytes 80..ff.
+ * The ICU ISO-2022 converter does not handle this - and has no information
+ * about which subconverter would have to be shifted vs. which is designed
+ * for 7-bit ISO-2022.
+ *
+ * Markus Scherer 2003-dec-03
+ */
+#endif
+
+static const char SHIFT_IN_STR[] = "\x0F";
+static const char SHIFT_OUT_STR[] = "\x0E";
+
+#define CR 0x0D
+#define LF 0x0A
+#define H_TAB 0x09
+#define V_TAB 0x0B
+#define SPACE 0x20
+
+enum {
+ HWKANA_START=0xff61,
+ HWKANA_END=0xff9f
+};
+
+/*
+ * 94-character sets with native byte values A1..FE are encoded in ISO 2022
+ * as bytes 21..7E. (Subtract 0x80.)
+ * 96-character sets with native byte values A0..FF are encoded in ISO 2022
+ * as bytes 20..7F. (Subtract 0x80.)
+ * Do not encode C1 control codes with native bytes 80..9F
+ * as bytes 00..1F (C0 control codes).
+ */
+enum {
+ GR94_START=0xa1,
+ GR94_END=0xfe,
+ GR96_START=0xa0,
+ GR96_END=0xff
+};
+
+/*
+ * ISO 2022 control codes must not be converted from Unicode
+ * because they would mess up the byte stream.
+ * The bit mask 0x0800c000 has bits set at bit positions 0xe, 0xf, 0x1b
+ * corresponding to SO, SI, and ESC.
+ */
+#define IS_2022_CONTROL(c) (((c)<0x20) && (((uint32_t)1<<(c))&0x0800c000)!=0)
+
+/* for ISO-2022-JP and -CN implementations */
+typedef enum {
+ /* shared values */
+ INVALID_STATE=-1,
+ ASCII = 0,
+
+ SS2_STATE=0x10,
+ SS3_STATE,
+
+ /* JP */
+ ISO8859_1 = 1 ,
+ ISO8859_7 = 2 ,
+ JISX201 = 3,
+ JISX208 = 4,
+ JISX212 = 5,
+ GB2312 =6,
+ KSC5601 =7,
+ HWKANA_7BIT=8, /* Halfwidth Katakana 7 bit */
+
+ /* CN */
+ /* the first few enum constants must keep their values because they correspond to myConverterArray[] */
+ GB2312_1=1,
+ ISO_IR_165=2,
+ CNS_11643=3,
+
+ /*
+ * these are used in StateEnum and ISO2022State variables,
+ * but CNS_11643 must be used to index into myConverterArray[]
+ */
+ CNS_11643_0=0x20,
+ CNS_11643_1,
+ CNS_11643_2,
+ CNS_11643_3,
+ CNS_11643_4,
+ CNS_11643_5,
+ CNS_11643_6,
+ CNS_11643_7
+} StateEnum;
+
+/* is the StateEnum charset value for a DBCS charset? */
+#define IS_JP_DBCS(cs) (JISX208<=(cs) && (cs)<=KSC5601)
+
+#define CSM(cs) ((uint16_t)1<<(cs))
+
+/*
+ * Each of these charset masks (with index x) contains a bit for a charset in exact correspondence
+ * to whether that charset is used in the corresponding version x of ISO_2022,locale=ja,version=x
+ *
+ * Note: The converter uses some leniency:
+ * - The escape sequence ESC ( I for half-width 7-bit Katakana is recognized in
+ * all versions, not just JIS7 and JIS8.
+ * - ICU does not distinguish between different versions of JIS X 0208.
+ */
+static const uint16_t jpCharsetMasks[5]={
+ CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT),
+ CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212),
+ CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7),
+ CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7),
+ CSM(ASCII)|CSM(JISX201)|CSM(JISX208)|CSM(HWKANA_7BIT)|CSM(JISX212)|CSM(GB2312)|CSM(KSC5601)|CSM(ISO8859_1)|CSM(ISO8859_7)
+};
+
+typedef enum {
+ ASCII1=0,
+ LATIN1,
+ SBCS,
+ DBCS,
+ MBCS,
+ HWKANA
+}Cnv2022Type;
+
+typedef struct ISO2022State {
+ int8_t cs[4]; /* charset number for SI (G0)/SO (G1)/SS2 (G2)/SS3 (G3) */
+ int8_t g; /* 0..3 for G0..G3 (SI/SO/SS2/SS3) */
+ int8_t prevG; /* g before single shift (SS2 or SS3) */
+} ISO2022State;
+
+#define UCNV_OPTIONS_VERSION_MASK 0xf
+#define UCNV_2022_MAX_CONVERTERS 10
+
+typedef struct{
+ UConverterSharedData *myConverterArray[UCNV_2022_MAX_CONVERTERS];
+ UConverter *currentConverter;
+ Cnv2022Type currentType;
+ ISO2022State toU2022State, fromU2022State;
+ uint32_t key;
+ uint32_t version;
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ UBool isFirstBuffer;
+#endif
+ char name[30];
+ char locale[3];
+}UConverterDataISO2022;
+
+/* Protos */
+/* ISO-2022 ----------------------------------------------------------------- */
+
+/*Forward declaration */
+U_CFUNC void
+ucnv_fromUnicode_UTF8(UConverterFromUnicodeArgs * args,
+ UErrorCode * err);
+U_CFUNC void
+ucnv_fromUnicode_UTF8_OFFSETS_LOGIC(UConverterFromUnicodeArgs * args,
+ UErrorCode * err);
+
+#define ESC_2022 0x1B /*ESC*/
+
+typedef enum
+{
+ INVALID_2022 = -1, /*Doesn't correspond to a valid iso 2022 escape sequence*/
+ VALID_NON_TERMINAL_2022 = 0, /*so far corresponds to a valid iso 2022 escape sequence*/
+ VALID_TERMINAL_2022 = 1, /*corresponds to a valid iso 2022 escape sequence*/
+ VALID_MAYBE_TERMINAL_2022 = 2 /*so far matches one iso 2022 escape sequence, but by adding more characters might match another escape sequence*/
+} UCNV_TableStates_2022;
+
+/*
+* The way these state transition arrays work is:
+* ex : ESC$B is the sequence for JISX208
+* a) First Iteration: char is ESC
+* i) Get the value of ESC from normalize_esq_chars_2022[] with int value of ESC as index
+* int x = normalize_esq_chars_2022[27] which is equal to 1
+* ii) Search for this value in escSeqStateTable_Key_2022[]
+* value of x is stored at escSeqStateTable_Key_2022[0]
+* iii) Save this index as offset
+* iv) Get state of this sequence from escSeqStateTable_Value_2022[]
+* escSeqStateTable_Value_2022[offset], which is VALID_NON_TERMINAL_2022
+* b) Switch on this state and continue to next char
+* i) Get the value of $ from normalize_esq_chars_2022[] with int value of $ as index
+* which is normalize_esq_chars_2022[36] == 4
+* ii) x is currently 1(from above)
+* x<<=5 -- x is now 32
+* x+=normalize_esq_chars_2022[36]
+* now x is 36
+* iii) Search for this value in escSeqStateTable_Key_2022[]
+* value of x is stored at escSeqStateTable_Key_2022[2], so offset is 2
+* iv) Get state of this sequence from escSeqStateTable_Value_2022[]
+* escSeqStateTable_Value_2022[offset], which is VALID_NON_TERMINAL_2022
+* c) Switch on this state and continue to next char
+* i) Get the value of B from normalize_esq_chars_2022[] with int value of B as index
+* ii) x is currently 36 (from above)
+* x<<=5 -- x is now 1152
+* x+=normalize_esq_chars_2022[66]
+* now x is 1161
+* iii) Search for this value in escSeqStateTable_Key_2022[]
+* value of x is stored at escSeqStateTable_Key_2022[21], so offset is 21
+* iv) Get state of this sequence from escSeqStateTable_Value_2022[21]
+* escSeqStateTable_Value_2022[offset], which is VALID_TERMINAL_2022
+* v) Get the converter name form escSeqStateTable_Result_2022[21] which is JISX208
+*/
+
+
+/*Below are the 3 arrays depicting a state transition table*/
+static const int8_t normalize_esq_chars_2022[256] = {
+/* 0 1 2 3 4 5 6 7 8 9 */
+
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,4 ,7 ,29 ,0
+ ,2 ,24 ,26 ,27 ,0 ,3 ,23 ,6 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,5 ,8 ,9 ,10 ,11 ,12
+ ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,25 ,28
+ ,0 ,0 ,21 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,22 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ ,0 ,0 ,0 ,0 ,0 ,0
+};
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+/*
+ * When the generic ISO-2022 converter is completely removed, not just disabled
+ * per #ifdef, then the following state table and the associated tables that are
+ * dimensioned with MAX_STATES_2022 should be trimmed.
+ *
+ * Especially, VALID_MAYBE_TERMINAL_2022 will not be used any more, and all of
+ * the associated escape sequences starting with ESC ( B should be removed.
+ * This includes the ones with key values 1097 and all of the ones above 1000000.
+ *
+ * For the latter, the tables can simply be truncated.
+ * For the former, since the tables must be kept parallel, it is probably best
+ * to simply duplicate an adjacent table cell, parallel in all tables.
+ *
+ * It may make sense to restructure the tables, especially by using small search
+ * tables for the variants instead of indexing them parallel to the table here.
+ */
+#endif
+
+#define MAX_STATES_2022 74
+static const int32_t escSeqStateTable_Key_2022[MAX_STATES_2022] = {
+/* 0 1 2 3 4 5 6 7 8 9 */
+
+ 1 ,34 ,36 ,39 ,55 ,57 ,60 ,61 ,1093 ,1096
+ ,1097 ,1098 ,1099 ,1100 ,1101 ,1102 ,1103 ,1104 ,1105 ,1106
+ ,1109 ,1154 ,1157 ,1160 ,1161 ,1176 ,1178 ,1179 ,1254 ,1257
+ ,1768 ,1773 ,1957 ,35105 ,36933 ,36936 ,36937 ,36938 ,36939 ,36940
+ ,36942 ,36943 ,36944 ,36945 ,36946 ,36947 ,36948 ,37640 ,37642 ,37644
+ ,37646 ,37711 ,37744 ,37745 ,37746 ,37747 ,37748 ,40133 ,40136 ,40138
+ ,40139 ,40140 ,40141 ,1123363 ,35947624 ,35947625 ,35947626 ,35947627 ,35947629 ,35947630
+ ,35947631 ,35947635 ,35947636 ,35947638
+};
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+
+static const char* const escSeqStateTable_Result_2022[MAX_STATES_2022] = {
+ /* 0 1 2 3 4 5 6 7 8 9 */
+
+ NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"latin1" ,"latin1"
+ ,"latin1" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"ibm-865" ,"JISX0201" ,"JISX0201" ,"latin1"
+ ,"latin1" ,NULL ,"JISX-208" ,"ibm-5478" ,"JISX-208" ,NULL ,NULL ,NULL ,NULL ,"UTF8"
+ ,"ISO-8859-1" ,"ISO-8859-7" ,"JIS-X-208" ,NULL ,"ibm-955" ,"ibm-367" ,"ibm-952" ,"ibm-949" ,"JISX-212" ,"ibm-1383"
+ ,"ibm-952" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-964" ,"ibm-5478" ,"ibm-949" ,"ISO-IR-165"
+ ,"CNS-11643-1992,1" ,"CNS-11643-1992,2" ,"CNS-11643-1992,3" ,"CNS-11643-1992,4" ,"CNS-11643-1992,5" ,"CNS-11643-1992,6" ,"CNS-11643-1992,7" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian"
+ ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,"UTF16_PlatformEndian" ,NULL ,"latin1" ,"ibm-912" ,"ibm-913" ,"ibm-914" ,"ibm-813" ,"ibm-1089"
+ ,"ibm-920" ,"ibm-915" ,"ibm-915" ,"latin1"
+};
+
+#endif
+
+static const UCNV_TableStates_2022 escSeqStateTable_Value_2022[MAX_STATES_2022] = {
+/* 0 1 2 3 4 5 6 7 8 9 */
+ VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_MAYBE_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_NON_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+ ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022 ,VALID_TERMINAL_2022
+};
+
+
+/* Type def for refactoring changeState_2022 code*/
+typedef enum{
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ ISO_2022=0,
+#endif
+ ISO_2022_JP=1,
+ ISO_2022_KR=2,
+ ISO_2022_CN=3
+} Variant2022;
+
+/*********** ISO 2022 Converter Protos ***********/
+static void
+_ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode);
+
+static void
+ _ISO2022Close(UConverter *converter);
+
+static void
+_ISO2022Reset(UConverter *converter, UConverterResetChoice choice);
+
+static const char*
+_ISO2022getName(const UConverter* cnv);
+
+static void
+_ISO_2022_WriteSub(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode *err);
+
+static UConverter *
+_ISO_2022_SafeClone(const UConverter *cnv, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status);
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+static void
+T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC(UConverterToUnicodeArgs* args, UErrorCode* err);
+#endif
+
+/*const UConverterSharedData _ISO2022Data;*/
+static const UConverterSharedData _ISO2022JPData;
+static const UConverterSharedData _ISO2022KRData;
+static const UConverterSharedData _ISO2022CNData;
+
+/*************** Converter implementations ******************/
+
+/* The purpose of this function is to get around gcc compiler warnings. */
+static U_INLINE void
+fromUWriteUInt8(UConverter *cnv,
+ const char *bytes, int32_t length,
+ uint8_t **target, const char *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode)
+{
+ char *targetChars = (char *)*target;
+ ucnv_fromUWriteBytes(cnv, bytes, length, &targetChars, targetLimit,
+ offsets, sourceIndex, pErrorCode);
+ *target = (uint8_t*)targetChars;
+
+}
+
+static U_INLINE void
+setInitialStateToUnicodeKR(UConverter* converter, UConverterDataISO2022 *myConverterData){
+ if(myConverterData->version == 1) {
+ UConverter *cnv = myConverterData->currentConverter;
+
+ cnv->toUnicodeStatus=0; /* offset */
+ cnv->mode=0; /* state */
+ cnv->toULength=0; /* byteIndex */
+ }
+}
+
+static U_INLINE void
+setInitialStateFromUnicodeKR(UConverter* converter,UConverterDataISO2022 *myConverterData){
+ /* in ISO-2022-KR the designator sequence appears only once
+ * in a file so we append it only once
+ */
+ if( converter->charErrorBufferLength==0){
+
+ converter->charErrorBufferLength = 4;
+ converter->charErrorBuffer[0] = 0x1b;
+ converter->charErrorBuffer[1] = 0x24;
+ converter->charErrorBuffer[2] = 0x29;
+ converter->charErrorBuffer[3] = 0x43;
+ }
+ if(myConverterData->version == 1) {
+ UConverter *cnv = myConverterData->currentConverter;
+
+ cnv->fromUChar32=0;
+ cnv->fromUnicodeStatus=1; /* prevLength */
+ }
+}
+
+static void
+_ISO2022Open(UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *errorCode){
+
+ char myLocale[6]={' ',' ',' ',' ',' ',' '};
+
+ cnv->extraInfo = uprv_malloc (sizeof (UConverterDataISO2022));
+ if(cnv->extraInfo != NULL) {
+ UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) cnv->extraInfo;
+ uint32_t version;
+
+ uprv_memset(myConverterData, 0, sizeof(UConverterDataISO2022));
+ myConverterData->currentType = ASCII1;
+ cnv->fromUnicodeStatus =FALSE;
+ if(locale){
+ uprv_strncpy(myLocale, locale, sizeof(myLocale));
+ }
+ version = options & UCNV_OPTIONS_VERSION_MASK;
+ myConverterData->version = version;
+ if(myLocale[0]=='j' && (myLocale[1]=='a'|| myLocale[1]=='p') &&
+ (myLocale[2]=='_' || myLocale[2]=='\0'))
+ {
+ size_t len=0;
+ /* open the required converters and cache them */
+ if(jpCharsetMasks[version]&CSM(ISO8859_7)) {
+ myConverterData->myConverterArray[ISO8859_7]= ucnv_loadSharedData("ISO8859_7", NULL, errorCode);
+ }
+ myConverterData->myConverterArray[JISX201] = ucnv_loadSharedData("JISX0201", NULL, errorCode);
+ myConverterData->myConverterArray[JISX208] = ucnv_loadSharedData("jisx-208", NULL, errorCode);
+ if(jpCharsetMasks[version]&CSM(JISX212)) {
+ myConverterData->myConverterArray[JISX212] = ucnv_loadSharedData("jisx-212", NULL, errorCode);
+ }
+ if(jpCharsetMasks[version]&CSM(GB2312)) {
+ myConverterData->myConverterArray[GB2312] = ucnv_loadSharedData("ibm-5478", NULL, errorCode); /* gb_2312_80-1 */
+ }
+ if(jpCharsetMasks[version]&CSM(KSC5601)) {
+ myConverterData->myConverterArray[KSC5601] = ucnv_loadSharedData("ksc_5601", NULL, errorCode);
+ }
+
+ /* set the function pointers to appropriate funtions */
+ cnv->sharedData=(UConverterSharedData*)(&_ISO2022JPData);
+ uprv_strcpy(myConverterData->locale,"ja");
+
+ (void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ja,version=");
+ len = uprv_strlen(myConverterData->name);
+ myConverterData->name[len]=(char)(myConverterData->version+(int)'0');
+ myConverterData->name[len+1]='\0';
+ }
+ else if(myLocale[0]=='k' && (myLocale[1]=='o'|| myLocale[1]=='r') &&
+ (myLocale[2]=='_' || myLocale[2]=='\0'))
+ {
+ if (version==1){
+ myConverterData->currentConverter=
+ ucnv_open("icu-internal-25546",errorCode);
+
+ if (U_FAILURE(*errorCode)) {
+ _ISO2022Close(cnv);
+ return;
+ }
+
+ (void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ko,version=1");
+ uprv_memcpy(cnv->subChars, myConverterData->currentConverter->subChars, 4);
+ cnv->subCharLen = myConverterData->currentConverter->subCharLen;
+ }else{
+ myConverterData->currentConverter=ucnv_open("ibm-949",errorCode);
+
+ if (U_FAILURE(*errorCode)) {
+ _ISO2022Close(cnv);
+ return;
+ }
+
+ myConverterData->version = 0;
+ (void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=ko,version=0");
+ }
+
+ /* initialize the state variables */
+ setInitialStateToUnicodeKR(cnv, myConverterData);
+ setInitialStateFromUnicodeKR(cnv, myConverterData);
+
+ /* set the function pointers to appropriate funtions */
+ cnv->sharedData=(UConverterSharedData*)&_ISO2022KRData;
+ uprv_strcpy(myConverterData->locale,"ko");
+ }
+ else if(((myLocale[0]=='z' && myLocale[1]=='h') || (myLocale[0]=='c'&& myLocale[1]=='n'))&&
+ (myLocale[2]=='_' || myLocale[2]=='\0'))
+ {
+
+ /* open the required converters and cache them */
+ myConverterData->myConverterArray[GB2312_1] = ucnv_loadSharedData("ibm-5478", NULL, errorCode);
+ if(version==1) {
+ myConverterData->myConverterArray[ISO_IR_165] = ucnv_loadSharedData("iso-ir-165", NULL, errorCode);
+ }
+ myConverterData->myConverterArray[CNS_11643] = ucnv_loadSharedData("cns-11643-1992", NULL, errorCode);
+
+
+ /* set the function pointers to appropriate funtions */
+ cnv->sharedData=(UConverterSharedData*)&_ISO2022CNData;
+ uprv_strcpy(myConverterData->locale,"cn");
+
+ if (version==1){
+ (void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=zh,version=1");
+ }else{
+ myConverterData->version = 0;
+ (void)uprv_strcpy(myConverterData->name,"ISO_2022,locale=zh,version=0");
+ }
+ }
+ else{
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ myConverterData->isFirstBuffer = TRUE;
+
+ /* append the UTF-8 escape sequence */
+ cnv->charErrorBufferLength = 3;
+ cnv->charErrorBuffer[0] = 0x1b;
+ cnv->charErrorBuffer[1] = 0x25;
+ cnv->charErrorBuffer[2] = 0x42;
+
+ cnv->sharedData=(UConverterSharedData*)&_ISO2022Data;
+ /* initialize the state variables */
+ uprv_strcpy(myConverterData->name,"ISO_2022");
+#else
+ *errorCode = U_UNSUPPORTED_ERROR;
+ return;
+#endif
+ }
+
+ cnv->maxBytesPerUChar=cnv->sharedData->staticData->maxBytesPerChar;
+
+ if(U_FAILURE(*errorCode)) {
+ _ISO2022Close(cnv);
+ }
+ } else {
+ *errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+
+static void
+_ISO2022Close(UConverter *converter) {
+ UConverterDataISO2022* myData =(UConverterDataISO2022 *) (converter->extraInfo);
+ UConverterSharedData **array = myData->myConverterArray;
+ int32_t i;
+
+ if (converter->extraInfo != NULL) {
+ /*close the array of converter pointers and free the memory*/
+ for (i=0; icurrentConverter);
+
+ if(!converter->isExtraLocal){
+ uprv_free (converter->extraInfo);
+ converter->extraInfo = NULL;
+ }
+ }
+}
+
+static void
+_ISO2022Reset(UConverter *converter, UConverterResetChoice choice) {
+ UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) (converter->extraInfo);
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ uprv_memset(&myConverterData->toU2022State, 0, sizeof(ISO2022State));
+ myConverterData->key = 0;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ uprv_memset(&myConverterData->fromU2022State, 0, sizeof(ISO2022State));
+ }
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ if(myConverterData->locale[0] == 0){
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ myConverterData->isFirstBuffer = TRUE;
+ myConverterData->key = 0;
+ if (converter->mode == UCNV_SO){
+ ucnv_close (myConverterData->currentConverter);
+ myConverterData->currentConverter=NULL;
+ }
+ converter->mode = UCNV_SI;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ /* re-append UTF-8 escape sequence */
+ converter->charErrorBufferLength = 3;
+ converter->charErrorBuffer[0] = 0x1b;
+ converter->charErrorBuffer[1] = 0x28;
+ converter->charErrorBuffer[2] = 0x42;
+ }
+ }
+ else
+#endif
+ {
+ /* reset the state variables */
+ if(myConverterData->locale[0] == 'k'){
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ setInitialStateToUnicodeKR(converter, myConverterData);
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ setInitialStateFromUnicodeKR(converter, myConverterData);
+ }
+ }
+ }
+}
+
+static const char*
+_ISO2022getName(const UConverter* cnv){
+ if(cnv->extraInfo){
+ UConverterDataISO2022* myData= (UConverterDataISO2022*)cnv->extraInfo;
+ return myData->name;
+ }
+ return NULL;
+}
+
+
+/*************** to unicode *******************/
+/****************************************************************************
+ * Recognized escape sequences are
+ * (B ASCII
+ * .A ISO-8859-1
+ * .F ISO-8859-7
+ * (J JISX-201
+ * (I JISX-201
+ * $B JISX-208
+ * $@ JISX-208
+ * $(D JISX-212
+ * $A GB2312
+ * $(C KSC5601
+ */
+static const StateEnum nextStateToUnicodeJP[MAX_STATES_2022]= {
+/* 0 1 2 3 4 5 6 7 8 9 */
+ INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,SS2_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,ASCII ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,JISX201 ,HWKANA_7BIT ,JISX201 ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,JISX208 ,GB2312 ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,ISO8859_1 ,ISO8859_7 ,JISX208 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,KSC5601 ,JISX212 ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+};
+
+/*************** to unicode *******************/
+static const StateEnum nextStateToUnicodeCN[MAX_STATES_2022]= {
+/* 0 1 2 3 4 5 6 7 8 9 */
+ INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,SS2_STATE ,SS3_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,GB2312_1 ,INVALID_STATE ,ISO_IR_165
+ ,CNS_11643_1 ,CNS_11643_2 ,CNS_11643_3 ,CNS_11643_4 ,CNS_11643_5 ,CNS_11643_6 ,CNS_11643_7 ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+ ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE ,INVALID_STATE
+};
+
+
+static UCNV_TableStates_2022
+getKey_2022(char c,int32_t* key,int32_t* offset){
+ int32_t togo;
+ int32_t low = 0;
+ int32_t hi = MAX_STATES_2022;
+ int32_t oldmid=0;
+
+ togo = normalize_esq_chars_2022[(uint8_t)c];
+ if(togo == 0) {
+ /* not a valid character anywhere in an escape sequence */
+ *key = 0;
+ *offset = 0;
+ return INVALID_2022;
+ }
+ togo = (*key << 5) + togo;
+
+ while (hi != low) /*binary search*/{
+
+ register int32_t mid = (hi+low) >> 1; /*Finds median*/
+
+ if (mid == oldmid)
+ break;
+
+ if (escSeqStateTable_Key_2022[mid] > togo){
+ hi = mid;
+ }
+ else if (escSeqStateTable_Key_2022[mid] < togo){
+ low = mid;
+ }
+ else /*we found it*/{
+ *key = togo;
+ *offset = mid;
+ return escSeqStateTable_Value_2022[mid];
+ }
+ oldmid = mid;
+
+ }
+
+ *key = 0;
+ *offset = 0;
+ return INVALID_2022;
+}
+
+/*runs through a state machine to determine the escape sequence - codepage correspondance
+ */
+static void
+changeState_2022(UConverter* _this,
+ const char** source,
+ const char* sourceLimit,
+ Variant2022 var,
+ UErrorCode* err){
+ UCNV_TableStates_2022 value;
+ UConverterDataISO2022* myData2022 = ((UConverterDataISO2022*)_this->extraInfo);
+ uint32_t key = myData2022->key;
+ int32_t offset = 0;
+ char c;
+
+ value = VALID_NON_TERMINAL_2022;
+ while (*source < sourceLimit) {
+ c = *(*source)++;
+ _this->toUBytes[_this->toULength++]=(uint8_t)c;
+ value = getKey_2022(c,(int32_t *) &key, &offset);
+
+ switch (value){
+
+ case VALID_NON_TERMINAL_2022 :
+ /* continue with the loop */
+ break;
+
+ case VALID_TERMINAL_2022:
+ key = 0;
+ goto DONE;
+
+ case INVALID_2022:
+ goto DONE;
+
+ case VALID_MAYBE_TERMINAL_2022:
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ /* ESC ( B is ambiguous only for ISO_2022 itself */
+ if(var == ISO_2022) {
+ /* discard toUBytes[] for ESC ( B because this sequence is correct and complete */
+ _this->toULength = 0;
+
+ /* TODO need to indicate that ESC ( B was seen; if failure, then need to replay from source or from MBCS-style replay */
+
+ /* continue with the loop */
+ value = VALID_NON_TERMINAL_2022;
+ break;
+ } else
+#endif
+ {
+ /* not ISO_2022 itself, finish here */
+ value = VALID_TERMINAL_2022;
+ key = 0;
+ goto DONE;
+ }
+ }
+ }
+
+DONE:
+ myData2022->key = key;
+
+ if (value == VALID_NON_TERMINAL_2022) {
+ /* indicate that the escape sequence is incomplete: key!=0 */
+ return;
+ } else if (value == INVALID_2022 ) {
+ *err = U_ILLEGAL_ESCAPE_SEQUENCE;
+ return;
+ } else /* value == VALID_TERMINAL_2022 */ {
+ switch(var){
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ case ISO_2022:
+ {
+ const char *chosenConverterName = escSeqStateTable_Result_2022[offset];
+ if(chosenConverterName == NULL) {
+ /* SS2 or SS3 */
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ return;
+ }
+
+ _this->mode = UCNV_SI;
+ ucnv_close(myData2022->currentConverter);
+ myData2022->currentConverter = myUConverter = ucnv_open(chosenConverterName, err);
+ if(U_SUCCESS(*err)) {
+ myUConverter->fromCharErrorBehaviour = UCNV_TO_U_CALLBACK_STOP;
+ _this->mode = UCNV_SO;
+ }
+ break;
+ }
+#endif
+ case ISO_2022_JP:
+ {
+ StateEnum tempState=nextStateToUnicodeJP[offset];
+ switch(tempState) {
+ case INVALID_STATE:
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ break;
+ case SS2_STATE:
+ if(myData2022->toU2022State.cs[2]!=0) {
+ if(myData2022->toU2022State.g<2) {
+ myData2022->toU2022State.prevG=myData2022->toU2022State.g;
+ }
+ myData2022->toU2022State.g=2;
+ } else {
+ /* illegal to have SS2 before a matching designator */
+ *err = U_ILLEGAL_ESCAPE_SEQUENCE;
+ }
+ break;
+ /* case SS3_STATE: not used in ISO-2022-JP-x */
+ case ISO8859_1:
+ case ISO8859_7:
+ if((jpCharsetMasks[myData2022->version] & CSM(tempState)) == 0) {
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ } else {
+ /* G2 charset for SS2 */
+ myData2022->toU2022State.cs[2]=(int8_t)tempState;
+ }
+ break;
+ default:
+ if((jpCharsetMasks[myData2022->version] & CSM(tempState)) == 0) {
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ } else {
+ /* G0 charset */
+ myData2022->toU2022State.cs[0]=(int8_t)tempState;
+ }
+ break;
+ }
+ }
+ break;
+ case ISO_2022_CN:
+ {
+ StateEnum tempState=nextStateToUnicodeCN[offset];
+ switch(tempState) {
+ case INVALID_STATE:
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ break;
+ case SS2_STATE:
+ if(myData2022->toU2022State.cs[2]!=0) {
+ if(myData2022->toU2022State.g<2) {
+ myData2022->toU2022State.prevG=myData2022->toU2022State.g;
+ }
+ myData2022->toU2022State.g=2;
+ } else {
+ /* illegal to have SS2 before a matching designator */
+ *err = U_ILLEGAL_ESCAPE_SEQUENCE;
+ }
+ break;
+ case SS3_STATE:
+ if(myData2022->toU2022State.cs[3]!=0) {
+ if(myData2022->toU2022State.g<2) {
+ myData2022->toU2022State.prevG=myData2022->toU2022State.g;
+ }
+ myData2022->toU2022State.g=3;
+ } else {
+ /* illegal to have SS3 before a matching designator */
+ *err = U_ILLEGAL_ESCAPE_SEQUENCE;
+ }
+ break;
+ case ISO_IR_165:
+ if(myData2022->version==0) {
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ break;
+ }
+ /*fall through*/
+ case GB2312_1:
+ /*fall through*/
+ case CNS_11643_1:
+ myData2022->toU2022State.cs[1]=(int8_t)tempState;
+ break;
+ case CNS_11643_2:
+ myData2022->toU2022State.cs[2]=(int8_t)tempState;
+ break;
+ default:
+ /* other CNS 11643 planes */
+ if(myData2022->version==0) {
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ } else {
+ myData2022->toU2022State.cs[3]=(int8_t)tempState;
+ }
+ break;
+ }
+ }
+ break;
+ case ISO_2022_KR:
+ if(offset==0x30){
+ /* nothing to be done, just accept this one escape sequence */
+ } else {
+ *err = U_UNSUPPORTED_ESCAPE_SEQUENCE;
+ }
+ break;
+
+ default:
+ *err = U_ILLEGAL_ESCAPE_SEQUENCE;
+ break;
+ }
+ }
+ if(U_SUCCESS(*err)) {
+ _this->toULength = 0;
+ }
+}
+
+/*Checks the characters of the buffer against valid 2022 escape sequences
+*if the match we return a pointer to the initial start of the sequence otherwise
+*we return sourceLimit
+*/
+/*for 2022 looks ahead in the stream
+ *to determine the longest possible convertible
+ *data stream
+ */
+static U_INLINE const char*
+getEndOfBuffer_2022(const char** source,
+ const char* sourceLimit,
+ UBool flush){
+
+ const char* mySource = *source;
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ if (*source >= sourceLimit)
+ return sourceLimit;
+
+ do{
+
+ if (*mySource == ESC_2022){
+ int8_t i;
+ int32_t key = 0;
+ int32_t offset;
+ UCNV_TableStates_2022 value = VALID_NON_TERMINAL_2022;
+
+ /* Kludge: I could not
+ * figure out the reason for validating an escape sequence
+ * twice - once here and once in changeState_2022().
+ * is it possible to have an ESC character in a ISO2022
+ * byte stream which is valid in a code page? Is it legal?
+ */
+ for (i=0;
+ (mySource+i < sourceLimit)&&(value == VALID_NON_TERMINAL_2022);
+ i++) {
+ value = getKey_2022(*(mySource+i), &key, &offset);
+ }
+ if (value > 0 || *mySource==ESC_2022)
+ return mySource;
+
+ if ((value == VALID_NON_TERMINAL_2022)&&(!flush) )
+ return sourceLimit;
+ }
+ }while (++mySource < sourceLimit);
+
+ return sourceLimit;
+#else
+ while(mySource < sourceLimit && *mySource != ESC_2022) {
+ ++mySource;
+ }
+ return mySource;
+#endif
+}
+
+
+/* This inline function replicates code in _MBCSFromUChar32() function in ucnvmbcs.c
+ * any future change in _MBCSFromUChar32() function should be reflected here.
+ * @return number of bytes in *value; negative number if fallback; 0 if no mapping
+ */
+static U_INLINE int32_t
+MBCS_FROM_UCHAR32_ISO2022(UConverterSharedData* sharedData,
+ UChar32 c,
+ uint32_t* value,
+ UBool useFallback,
+ int outputType)
+{
+ const int32_t *cx;
+ const uint16_t *table;
+ uint32_t stage2Entry;
+ uint32_t myValue;
+ int32_t length;
+ const uint8_t *p;
+ /*
+ * TODO(markus): Use and require new, faster MBCS conversion table structures.
+ * Use internal version of ucnv_open() that verifies that the new structures are available,
+ * else U_INTERNAL_PROGRAM_ERROR.
+ */
+ /* BMP-only codepages are stored without stage 1 entries for supplementary code points */
+ if(c<0x10000 || (sharedData->mbcs.unicodeMask&UCNV_HAS_SUPPLEMENTARY)) {
+ table=sharedData->mbcs.fromUnicodeTable;
+ stage2Entry=MBCS_STAGE_2_FROM_U(table, c);
+ /* get the bytes and the length for the output */
+ if(outputType==MBCS_OUTPUT_2){
+ myValue=MBCS_VALUE_2_FROM_STAGE_2(sharedData->mbcs.fromUnicodeBytes, stage2Entry, c);
+ if(myValue<=0xff) {
+ length=1;
+ } else {
+ length=2;
+ }
+ } else /* outputType==MBCS_OUTPUT_3 */ {
+ p=MBCS_POINTER_3_FROM_STAGE_2(sharedData->mbcs.fromUnicodeBytes, stage2Entry, c);
+ myValue=((uint32_t)*p<<16)|((uint32_t)p[1]<<8)|p[2];
+ if(myValue<=0xff) {
+ length=1;
+ } else if(myValue<=0xffff) {
+ length=2;
+ } else {
+ length=3;
+ }
+ }
+ /*
+ * TODO(markus): Use Shift-JIS table for JIS X 0208, to save mapping table space.
+ * Pass in parameter for type of output bytes, for validation and shifting:
+ * - Direct: Pass bytes through, but forbid control codes 00-1F (except SI/SO/ESC) and space 20?
+ * (Need to allow some (TAB/LF/CR) or most of them for ASCII and maybe JIS X 0201.)
+ * - A1-FE: Subtract 80 after range check.
+ * - SJIS: Shift DBCS result to 21-7E x 21-7E.
+ */
+ /* is this code point assigned, or do we use fallbacks? */
+ if((stage2Entry&(1<<(16+(c&0xf))))!=0) {
+ /* assigned */
+ *value=myValue;
+ return length;
+ } else if(FROM_U_USE_FALLBACK(useFallback, c) && myValue!=0) {
+ /*
+ * We allow a 0 byte output if the "assigned" bit is set for this entry.
+ * There is no way with this data structure for fallback output
+ * to be a zero byte.
+ */
+ *value=myValue;
+ return -length;
+ }
+ }
+
+ cx=sharedData->mbcs.extIndexes;
+ if(cx!=NULL) {
+ return ucnv_extSimpleMatchFromU(cx, c, value, useFallback);
+ }
+
+ /* unassigned */
+ return 0;
+}
+
+/* This inline function replicates code in _MBCSSingleFromUChar32() function in ucnvmbcs.c
+ * any future change in _MBCSSingleFromUChar32() function should be reflected here.
+ * @param retval pointer to output byte
+ * @return 1 roundtrip byte 0 no mapping -1 fallback byte
+ */
+static U_INLINE int32_t
+MBCS_SINGLE_FROM_UCHAR32(UConverterSharedData* sharedData,
+ UChar32 c,
+ uint32_t* retval,
+ UBool useFallback)
+{
+ const uint16_t *table;
+ int32_t value;
+ /* BMP-only codepages are stored without stage 1 entries for supplementary code points */
+ if(c>=0x10000 && !(sharedData->mbcs.unicodeMask&UCNV_HAS_SUPPLEMENTARY)) {
+ return 0;
+ }
+ /* convert the Unicode code point in c into codepage bytes (same as in _MBCSFromUnicodeWithOffsets) */
+ table=sharedData->mbcs.fromUnicodeTable;
+ /* get the byte for the output */
+ value=MBCS_SINGLE_RESULT_FROM_U(table, (uint16_t *)sharedData->mbcs.fromUnicodeBytes, c);
+ /* is this code point assigned, or do we use fallbacks? */
+ *retval=(uint32_t)(value&0xff);
+ if(value>=0xf00) {
+ return 1; /* roundtrip */
+ } else if(useFallback ? value>=0x800 : value>=0xc00) {
+ return -1; /* fallback taken */
+ } else {
+ return 0; /* no mapping */
+ }
+}
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+
+/**********************************************************************************
+* ISO-2022 Converter
+*
+*
+*/
+
+static void
+T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC(UConverterToUnicodeArgs* args,
+ UErrorCode* err){
+ const char* mySourceLimit, *realSourceLimit;
+ const char* sourceStart;
+ const UChar* myTargetStart;
+ UConverter* saveThis;
+ UConverterDataISO2022* myData;
+ int8_t length;
+
+ saveThis = args->converter;
+ myData=((UConverterDataISO2022*)(saveThis->extraInfo));
+
+ realSourceLimit = args->sourceLimit;
+ while (args->source < realSourceLimit) {
+ if(myData->key == 0) { /* are we in the middle of an escape sequence? */
+ /*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
+ mySourceLimit = getEndOfBuffer_2022(&(args->source), realSourceLimit, args->flush);
+
+ if(args->source < mySourceLimit) {
+ if(myData->currentConverter==NULL) {
+ myData->currentConverter = ucnv_open("ASCII",err);
+ if(U_FAILURE(*err)){
+ return;
+ }
+
+ myData->currentConverter->fromCharErrorBehaviour = UCNV_TO_U_CALLBACK_STOP;
+ saveThis->mode = UCNV_SO;
+ }
+
+ /* convert to before the ESC or until the end of the buffer */
+ myData->isFirstBuffer=FALSE;
+ sourceStart = args->source;
+ myTargetStart = args->target;
+ args->converter = myData->currentConverter;
+ ucnv_toUnicode(args->converter,
+ &args->target,
+ args->targetLimit,
+ &args->source,
+ mySourceLimit,
+ args->offsets,
+ (UBool)(args->flush && mySourceLimit == realSourceLimit),
+ err);
+ args->converter = saveThis;
+
+ if (*err == U_BUFFER_OVERFLOW_ERROR) {
+ /* move the overflow buffer */
+ length = saveThis->UCharErrorBufferLength = myData->currentConverter->UCharErrorBufferLength;
+ myData->currentConverter->UCharErrorBufferLength = 0;
+ if(length > 0) {
+ uprv_memcpy(saveThis->UCharErrorBuffer,
+ myData->currentConverter->UCharErrorBuffer,
+ length*U_SIZEOF_UCHAR);
+ }
+ return;
+ }
+
+ /*
+ * At least one of:
+ * -Error while converting
+ * -Done with entire buffer
+ * -Need to write offsets or update the current offset
+ * (leave that up to the code in ucnv.c)
+ *
+ * or else we just stopped at an ESC byte and continue with changeState_2022()
+ */
+ if (U_FAILURE(*err) ||
+ (args->source == realSourceLimit) ||
+ (args->offsets != NULL && (args->target != myTargetStart || args->source != sourceStart) ||
+ (mySourceLimit < realSourceLimit && myData->currentConverter->toULength > 0))
+ ) {
+ /* copy partial or error input for truncated detection and error handling */
+ if(U_FAILURE(*err)) {
+ length = saveThis->invalidCharLength = myData->currentConverter->invalidCharLength;
+ if(length > 0) {
+ uprv_memcpy(saveThis->invalidCharBuffer, myData->currentConverter->invalidCharBuffer, length);
+ }
+ } else {
+ length = saveThis->toULength = myData->currentConverter->toULength;
+ if(length > 0) {
+ uprv_memcpy(saveThis->toUBytes, myData->currentConverter->toUBytes, length);
+ if(args->source < mySourceLimit) {
+ *err = U_TRUNCATED_CHAR_FOUND; /* truncated input before ESC */
+ }
+ }
+ }
+ return;
+ }
+ }
+ }
+
+ sourceStart = args->source;
+ changeState_2022(args->converter,
+ &(args->source),
+ realSourceLimit,
+ ISO_2022,
+ err);
+ if (U_FAILURE(*err) || (args->source != sourceStart && args->offsets != NULL)) {
+ /* let the ucnv.c code update its current offset */
+ return;
+ }
+ }
+}
+
+#endif
+
+/*
+ * To Unicode Callback helper function
+ */
+static void
+toUnicodeCallback(UConverter *cnv,
+ const uint32_t sourceChar, const uint32_t targetUniChar,
+ UErrorCode* err){
+ if(sourceChar>0xff){
+ cnv->toUBytes[0] = (uint8_t)(sourceChar>>8);
+ cnv->toUBytes[1] = (uint8_t)sourceChar;
+ cnv->toULength = 2;
+ }
+ else{
+ cnv->toUBytes[0] =(char) sourceChar;
+ cnv->toULength = 2;
+ }
+
+ if(targetUniChar == (missingCharMarker-1/*0xfffe*/)){
+ *err = U_INVALID_CHAR_FOUND;
+ }
+ else{
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+}
+
+/**************************************ISO-2022-JP*************************************************/
+
+/************************************** IMPORTANT **************************************************
+* The UConverter_fromUnicode_ISO2022_JP converter does not use ucnv_fromUnicode() functions for SBCS,DBCS and
+* MBCS; instead, the values are obtained directly by calling _MBCSFromUChar32().
+* The converter iterates over each Unicode codepoint
+* to obtain the equivalent codepoints from the codepages supported. Since the source buffer is
+* processed one char at a time it would make sense to reduce the extra processing a canned converter
+* would do as far as possible.
+*
+* If the implementation of these macros or structure of sharedData struct change in the future, make
+* sure that ISO-2022 is also changed.
+***************************************************************************************************
+*/
+
+/***************************************************************************************************
+* Rules for ISO-2022-jp encoding
+* (i) Escape sequences must be fully contained within a line they should not
+* span new lines or CRs
+* (ii) If the last character on a line is represented by two bytes then an ASCII or
+* JIS-Roman character escape sequence should follow before the line terminates
+* (iii) If the first character on the line is represented by two bytes then a two
+* byte character escape sequence should precede it
+* (iv) If no escape sequence is encountered then the characters are ASCII
+* (v) Latin(ISO-8859-1) and Greek(ISO-8859-7) characters must be designated to G2,
+* and invoked with SS2 (ESC N).
+* (vi) If there is any G0 designation in text, there must be a switch to
+* ASCII or to JIS X 0201-Roman before a space character (but not
+* necessarily before "ESC 4/14 2/0" or "ESC N ' '") or control
+* characters such as tab or CRLF.
+* (vi) Supported encodings:
+* ASCII, JISX201, JISX208, JISX212, GB2312, KSC5601, ISO-8859-1,ISO-8859-7
+*
+* source : RFC-1554
+*
+* JISX201, JISX208,JISX212 : new .cnv data files created
+* KSC5601 : alias to ibm-949 mapping table
+* GB2312 : alias to ibm-1386 mapping table
+* ISO-8859-1 : Algorithmic implemented as LATIN1 case
+* ISO-8859-7 : alisas to ibm-9409 mapping table
+*/
+
+/* preference order of JP charsets */
+static const StateEnum jpCharsetPref[]={
+ ASCII,
+ JISX201,
+ ISO8859_1,
+ ISO8859_7,
+ JISX208,
+ JISX212,
+ GB2312,
+ KSC5601,
+ HWKANA_7BIT
+};
+
+/*
+ * The escape sequences must be in order of the enum constants like JISX201 = 3,
+ * not in order of jpCharsetPref[]!
+ */
+static const char escSeqChars[][6] ={
+ "\x1B\x28\x42", /* (B ASCII */
+ "\x1B\x2E\x41", /* .A ISO-8859-1 */
+ "\x1B\x2E\x46", /* .F ISO-8859-7 */
+ "\x1B\x28\x4A", /* (J JISX-201 */
+ "\x1B\x24\x42", /* $B JISX-208 */
+ "\x1B\x24\x28\x44", /* $(D JISX-212 */
+ "\x1B\x24\x41", /* $A GB2312 */
+ "\x1B\x24\x28\x43", /* $(C KSC5601 */
+ "\x1B\x28\x49" /* (I HWKANA_7BIT */
+
+};
+static const int32_t escSeqCharsLen[] ={
+ 3, /* length of (B ASCII */
+ 3, /* length of .A ISO-8859-1 */
+ 3, /* length of .F ISO-8859-7 */
+ 3, /* length of (J JISX-201 */
+ 3, /* length of $B JISX-208 */
+ 4, /* length of $(D JISX-212 */
+ 3, /* length of $A GB2312 */
+ 4, /* length of $(C KSC5601 */
+ 3 /* length of (I HWKANA_7BIT */
+};
+
+/*
+* The iteration over various code pages works this way:
+* i) Get the currentState from myConverterData->currentState
+* ii) Check if the character is mapped to a valid character in the currentState
+* Yes -> a) set the initIterState to currentState
+* b) remain in this state until an invalid character is found
+* No -> a) go to the next code page and find the character
+* iii) Before changing the state increment the current state check if the current state
+* is equal to the intitIteration state
+* Yes -> A character that cannot be represented in any of the supported encodings
+* break and return a U_INVALID_CHARACTER error
+* No -> Continue and find the character in next code page
+*
+*
+* TODO: Implement a priority technique where the users are allowed to set the priority of code pages
+*/
+
+static void
+UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err) {
+ UConverter *cnv = args->converter;
+ UConverterDataISO2022 *converterData;
+ ISO2022State *pFromU2022State;
+ uint8_t *target = (uint8_t *) args->target;
+ const uint8_t *targetLimit = (const uint8_t *) args->targetLimit;
+ const UChar* source = args->source;
+ const UChar* sourceLimit = args->sourceLimit;
+ int32_t* offsets = args->offsets;
+ UChar32 sourceChar;
+ char buffer[8];
+ int32_t len, outLen;
+ int8_t choices[10];
+ int32_t choiceCount;
+ uint32_t targetValue = 0;
+ UBool useFallback;
+
+ int32_t i;
+ int8_t cs, g;
+
+ /* set up the state */
+ converterData = (UConverterDataISO2022*)cnv->extraInfo;
+ pFromU2022State = &converterData->fromU2022State;
+
+ choiceCount = 0;
+
+ /* check if the last codepoint of previous buffer was a lead surrogate*/
+ if((sourceChar = cnv->fromUChar32)!=0 && target< targetLimit) {
+ goto getTrail;
+ }
+
+ while(source < sourceLimit) {
+ if(target < targetLimit) {
+
+ sourceChar = *(source++);
+ /*check if the char is a First surrogate*/
+ if(UTF_IS_SURROGATE(sourceChar)) {
+ if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
+getTrail:
+ /*look ahead to find the trail surrogate*/
+ if(source < sourceLimit) {
+ /* test the following code unit */
+ UChar trail=(UChar) *source;
+ if(UTF_IS_SECOND_SURROGATE(trail)) {
+ source++;
+ sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
+ cnv->fromUChar32=0x00;
+ /* convert this supplementary code point */
+ /* exit this condition tree */
+ } else {
+ /* this is an unmatched lead code unit (1st surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ } else {
+ /* no more input */
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ } else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ }
+
+ /* do not convert SO/SI/ESC */
+ if(IS_2022_CONTROL(sourceChar)) {
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+
+ /* do the conversion */
+
+ if(choiceCount == 0) {
+ uint16_t csm;
+
+ /*
+ * The csm variable keeps track of which charsets are allowed
+ * and not used yet while building the choices[].
+ */
+ csm = jpCharsetMasks[converterData->version];
+ choiceCount = 0;
+
+ /* JIS7/8: try single-byte half-width Katakana before JISX208 */
+ if(converterData->version == 3 || converterData->version == 4) {
+ choices[choiceCount++] = (int8_t)HWKANA_7BIT;
+ }
+ /* Do not try single-byte half-width Katakana for other versions. */
+ csm &= ~CSM(HWKANA_7BIT);
+
+ /* try the current G0 charset */
+ choices[choiceCount++] = cs = pFromU2022State->cs[0];
+ csm &= ~CSM(cs);
+
+ /* try the current G2 charset */
+ if((cs = pFromU2022State->cs[2]) != 0) {
+ choices[choiceCount++] = cs;
+ csm &= ~CSM(cs);
+ }
+
+ /* try all the other possible charsets */
+ for(i = 0; i < LENGTHOF(jpCharsetPref); ++i) {
+ cs = (int8_t)jpCharsetPref[i];
+ if(CSM(cs) & csm) {
+ choices[choiceCount++] = cs;
+ csm &= ~CSM(cs);
+ }
+ }
+ }
+
+ cs = g = 0;
+ /*
+ * len==0: no mapping found yet
+ * len<0: found a fallback result: continue looking for a roundtrip but no further fallbacks
+ * len>0: found a roundtrip result, done
+ */
+ len = 0;
+ /*
+ * We will turn off useFallback after finding a fallback,
+ * but we still get fallbacks from PUA code points as usual.
+ * Therefore, we will also need to check that we don't overwrite
+ * an early fallback with a later one.
+ */
+ useFallback = cnv->useFallback;
+
+ for(i = 0; i < choiceCount && len <= 0; ++i) {
+ uint32_t value;
+ int32_t len2;
+ int8_t cs0 = choices[i];
+ switch(cs0) {
+ case ASCII:
+ if(sourceChar <= 0x7f) {
+ targetValue = (uint32_t)sourceChar;
+ len = 1;
+ cs = cs0;
+ g = 0;
+ }
+ break;
+ case ISO8859_1:
+ if(GR96_START <= sourceChar && sourceChar <= GR96_END) {
+ targetValue = (uint32_t)sourceChar - 0x80;
+ len = 1;
+ cs = cs0;
+ g = 2;
+ }
+ break;
+ case HWKANA_7BIT:
+ if((uint32_t)(HWKANA_END-sourceChar)<=(HWKANA_END-HWKANA_START)) {
+ if(converterData->version==3) {
+ /* JIS7: use G1 (SO) */
+ /* Shift U+FF61..U+FF9F to bytes 21..5F. */
+ targetValue = (uint32_t)(sourceChar - (HWKANA_START - 0x21));
+ len = 1;
+ pFromU2022State->cs[1] = cs = cs0; /* do not output an escape sequence */
+ g = 1;
+ } else if(converterData->version==4) {
+ /* JIS8: use 8-bit bytes with any single-byte charset, see escape sequence output below */
+ /* Shift U+FF61..U+FF9F to bytes A1..DF. */
+ targetValue = (uint32_t)(sourceChar - (HWKANA_START - 0xa1));
+ len = 1;
+
+ cs = pFromU2022State->cs[0];
+ if(IS_JP_DBCS(cs)) {
+ /* switch from a DBCS charset to JISX201 */
+ cs = (int8_t)JISX201;
+ }
+ /* else stay in the current G0 charset */
+ g = 0;
+ }
+ /* else do not use HWKANA_7BIT with other versions */
+ }
+ break;
+ case JISX201:
+ /* G0 SBCS */
+ len2 = MBCS_SINGLE_FROM_UCHAR32(
+ converterData->myConverterArray[cs0],
+ sourceChar, &value,
+ useFallback);
+ if(len2 != 0 && !(len2 < 0 && len != 0) && value <= 0x7f) {
+ targetValue = value;
+ len = len2;
+ cs = cs0;
+ g = 0;
+ useFallback = FALSE;
+ }
+ break;
+ case ISO8859_7:
+ /* G0 SBCS forced to 7-bit output */
+ len2 = MBCS_SINGLE_FROM_UCHAR32(
+ converterData->myConverterArray[cs0],
+ sourceChar, &value,
+ useFallback);
+ if(len2 != 0 && !(len2 < 0 && len != 0) && GR96_START <= value && value <= GR96_END) {
+ targetValue = value - 0x80;
+ len = len2;
+ cs = cs0;
+ g = 2;
+ useFallback = FALSE;
+ }
+ break;
+ default:
+ /* G0 DBCS */
+ len2 = MBCS_FROM_UCHAR32_ISO2022(
+ converterData->myConverterArray[cs0],
+ sourceChar, &value,
+ useFallback, MBCS_OUTPUT_2);
+ if(len2 == 2 || (len2 == -2 && len == 0)) { /* only accept DBCS: abs(len)==2 */
+ if(cs0 == KSC5601) {
+ /*
+ * Check for valid bytes for the encoding scheme.
+ * This is necessary because the sub-converter (windows-949)
+ * has a broader encoding scheme than is valid for 2022.
+ *
+ * Check that the result is a 2-byte value with each byte in the range A1..FE
+ * (strict EUC-KR DBCS) before accepting it and subtracting 0x80 from each byte
+ * to move it to the ISO 2022 range 21..7E.
+ */
+ if( (uint16_t)(value - 0xa1a1) <= (0xfefe - 0xa1a1) &&
+ (uint8_t)(value - 0xa1) <= (0xfe - 0xa1)
+ ) {
+ value -= 0x8080; /* shift down to 21..7e byte range */
+ } else {
+ break; /* not valid for ISO 2022 */
+ }
+ }
+ targetValue = value;
+ len = len2;
+ cs = cs0;
+ g = 0;
+ useFallback = FALSE;
+ }
+ break;
+ }
+ }
+
+ if(len != 0) {
+ if(len < 0) {
+ len = -len; /* fallback */
+ }
+ outLen = 0; /* count output bytes */
+
+ /* write SI if necessary (only for JIS7) */
+ if(pFromU2022State->g == 1 && g == 0) {
+ buffer[outLen++] = UCNV_SI;
+ pFromU2022State->g = 0;
+ }
+
+ /* write the designation sequence if necessary */
+ if(cs != pFromU2022State->cs[g]) {
+ int32_t escLen = escSeqCharsLen[cs];
+ uprv_memcpy(buffer + outLen, escSeqChars[cs], escLen);
+ outLen += escLen;
+ pFromU2022State->cs[g] = cs;
+
+ /* invalidate the choices[] */
+ choiceCount = 0;
+ }
+
+ /* write the shift sequence if necessary */
+ if(g != pFromU2022State->g) {
+ switch(g) {
+ /* case 0 handled before writing escapes */
+ case 1:
+ buffer[outLen++] = UCNV_SO;
+ pFromU2022State->g = 1;
+ break;
+ default: /* case 2 */
+ buffer[outLen++] = 0x1b;
+ buffer[outLen++] = 0x4e;
+ break;
+ /* no case 3: no SS3 in ISO-2022-JP-x */
+ }
+ }
+
+ /* write the output bytes */
+ if(len == 1) {
+ buffer[outLen++] = (char)targetValue;
+ } else /* len == 2 */ {
+ buffer[outLen++] = (char)(targetValue >> 8);
+ buffer[outLen++] = (char)targetValue;
+ }
+ } else {
+ /*
+ * if we cannot find the character after checking all codepages
+ * then this is an error
+ */
+ *err = U_INVALID_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+
+ if(sourceChar == CR || sourceChar == LF) {
+ /* reset the G2 state at the end of a line (conversion got us into ASCII or JISX201 already) */
+ pFromU2022State->cs[2] = 0;
+ choiceCount = 0;
+ }
+
+ /* output outLen>0 bytes in buffer[] */
+ if(outLen == 1) {
+ *target++ = buffer[0];
+ if(offsets) {
+ *offsets++ = (int32_t)(source - args->source - 1); /* -1: known to be ASCII */
+ }
+ } else if(outLen == 2 && (target + 2) <= targetLimit) {
+ *target++ = buffer[0];
+ *target++ = buffer[1];
+ if(offsets) {
+ int32_t sourceIndex = (int32_t)(source - args->source - U16_LENGTH(sourceChar));
+ *offsets++ = sourceIndex;
+ *offsets++ = sourceIndex;
+ }
+ } else {
+ fromUWriteUInt8(
+ cnv,
+ buffer, outLen,
+ &target, (const char *)targetLimit,
+ &offsets, (int32_t)(source - args->source - U16_LENGTH(sourceChar)),
+ err);
+ if(U_FAILURE(*err)) {
+ break;
+ }
+ }
+ } /* end if(myTargetIndexg!=0 || pFromU2022State->cs[0]!=ASCII) &&
+ args->flush && source>=sourceLimit && cnv->fromUChar32==0
+ ) {
+ int32_t sourceIndex;
+
+ outLen = 0;
+
+ if(pFromU2022State->g != 0) {
+ buffer[outLen++] = UCNV_SI;
+ pFromU2022State->g = 0;
+ }
+
+ if(pFromU2022State->cs[0] != ASCII) {
+ int32_t escLen = escSeqCharsLen[ASCII];
+ uprv_memcpy(buffer + outLen, escSeqChars[ASCII], escLen);
+ outLen += escLen;
+ pFromU2022State->cs[0] = (int8_t)ASCII;
+ }
+
+ /* get the source index of the last input character */
+ /*
+ * TODO this would be simpler and more reliable if we used a pair
+ * of sourceIndex/prevSourceIndex like in ucnvmbcs.c
+ * so that we could simply use the prevSourceIndex here;
+ * this code gives an incorrect result for the rare case of an unmatched
+ * trail surrogate that is alone in the last buffer of the text stream
+ */
+ sourceIndex=(int32_t)(source-args->source);
+ if(sourceIndex>0) {
+ --sourceIndex;
+ if( U16_IS_TRAIL(args->source[sourceIndex]) &&
+ (sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
+ ) {
+ --sourceIndex;
+ }
+ } else {
+ sourceIndex=-1;
+ }
+
+ fromUWriteUInt8(
+ cnv,
+ buffer, outLen,
+ &target, (const char *)targetLimit,
+ &offsets, sourceIndex,
+ err);
+ }
+
+ /*save the state and return */
+ args->source = source;
+ args->target = (char*)target;
+}
+
+/*************** to unicode *******************/
+
+static void
+UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
+ UErrorCode* err){
+ char tempBuf[3];
+ const char *mySource = (char *) args->source;
+ UChar *myTarget = args->target;
+ const char *mySourceLimit = args->sourceLimit;
+ uint32_t targetUniChar = 0x0000;
+ uint32_t mySourceChar = 0x0000;
+ UConverterDataISO2022* myData;
+ ISO2022State *pToU2022State;
+ StateEnum cs;
+
+ myData=(UConverterDataISO2022*)(args->converter->extraInfo);
+ pToU2022State = &myData->toU2022State;
+
+ if(myData->key != 0) {
+ /* continue with a partial escape sequence */
+ goto escape;
+ } else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
+ /* continue with a partial double-byte character */
+ mySourceChar = args->converter->toUBytes[0];
+ args->converter->toULength = 0;
+ cs = (StateEnum)pToU2022State->cs[pToU2022State->g];
+ goto getTrailByte;
+ }
+
+ while(mySource < mySourceLimit){
+
+ targetUniChar =missingCharMarker;
+
+ if(myTarget < args->targetLimit){
+
+ mySourceChar= (unsigned char) *mySource++;
+
+ switch(mySourceChar) {
+ case UCNV_SI:
+ if(myData->version==3) {
+ pToU2022State->g=0;
+ continue;
+ } else {
+ /* only JIS7 uses SI/SO, not ISO-2022-JP-x */
+ break;
+ }
+
+ case UCNV_SO:
+ if(myData->version==3) {
+ /* JIS7: switch to G1 half-width Katakana */
+ pToU2022State->cs[1] = (int8_t)HWKANA_7BIT;
+ pToU2022State->g=1;
+ continue;
+ } else {
+ /* only JIS7 uses SI/SO, not ISO-2022-JP-x */
+ break;
+ }
+
+ case ESC_2022:
+ mySource--;
+escape:
+ changeState_2022(args->converter,&(mySource),
+ mySourceLimit, ISO_2022_JP,err);
+
+ /* invalid or illegal escape sequence */
+ if(U_FAILURE(*err)){
+ args->target = myTarget;
+ args->source = mySource;
+ return;
+ }
+ continue;
+
+ /* ISO-2022-JP does not use single-byte (C1) SS2 and SS3 */
+
+ case CR:
+ /*falls through*/
+ case LF:
+ /* automatically reset to single-byte mode */
+ if((StateEnum)pToU2022State->cs[0] != ASCII && (StateEnum)pToU2022State->cs[0] != JISX201) {
+ pToU2022State->cs[0] = (int8_t)ASCII;
+ }
+ pToU2022State->cs[2] = 0;
+ pToU2022State->g = 0;
+ /* falls through */
+ default:
+ /* convert one or two bytes */
+ cs = (StateEnum)pToU2022State->cs[pToU2022State->g];
+ if( (uint8_t)(mySourceChar - 0xa1) <= (0xdf - 0xa1) && myData->version==4 &&
+ !IS_JP_DBCS(cs)
+ ) {
+ /* 8-bit halfwidth katakana in any single-byte mode for JIS8 */
+ targetUniChar = mySourceChar + (HWKANA_START - 0xa1);
+
+ /* return from a single-shift state to the previous one */
+ if(pToU2022State->g >= 2) {
+ pToU2022State->g=pToU2022State->prevG;
+ }
+ } else switch(cs) {
+ case ASCII:
+ if(mySourceChar <= 0x7f) {
+ targetUniChar = mySourceChar;
+ }
+ break;
+ case ISO8859_1:
+ if(mySourceChar <= 0x7f) {
+ targetUniChar = mySourceChar + 0x80;
+ }
+ /* return from a single-shift state to the previous one */
+ pToU2022State->g=pToU2022State->prevG;
+ break;
+ case ISO8859_7:
+ if(mySourceChar <= 0x7f) {
+ /* convert mySourceChar+0x80 to use a normal 8-bit table */
+ targetUniChar =
+ _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(
+ myData->myConverterArray[cs],
+ mySourceChar + 0x80);
+ }
+ /* return from a single-shift state to the previous one */
+ pToU2022State->g=pToU2022State->prevG;
+ break;
+ case JISX201:
+ if(mySourceChar <= 0x7f) {
+ targetUniChar =
+ _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(
+ myData->myConverterArray[cs],
+ mySourceChar);
+ }
+ break;
+ case HWKANA_7BIT:
+ if((uint8_t)(mySourceChar - 0x21) <= (0x5f - 0x21)) {
+ /* 7-bit halfwidth Katakana */
+ targetUniChar = mySourceChar + (HWKANA_START - 0x21);
+ }
+ break;
+ default:
+ /* G0 DBCS */
+ if(mySource < mySourceLimit) {
+ char trailByte;
+getTrailByte:
+ tempBuf[0] = (char) (mySourceChar);
+ tempBuf[1] = trailByte = *mySource++;
+ mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
+ targetUniChar = ucnv_MBCSSimpleGetNextUChar(myData->myConverterArray[cs], tempBuf, 2, FALSE);
+ } else {
+ args->converter->toUBytes[0] = (uint8_t)mySourceChar;
+ args->converter->toULength = 1;
+ goto endloop;
+ }
+ } /* End of inner switch */
+ break;
+ } /* End of outer switch */
+ if(targetUniChar < (missingCharMarker-1/*0xfffe*/)){
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ *(myTarget++)=(UChar)targetUniChar;
+ }
+ else if(targetUniChar > missingCharMarker){
+ /* disassemble the surrogate pair and write to output*/
+ targetUniChar-=0x0010000;
+ *myTarget = (UChar)(0xd800+(UChar)(targetUniChar>>10));
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ ++myTarget;
+ if(myTarget< args->targetLimit){
+ *myTarget = (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ ++myTarget;
+ }else{
+ args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++]=
+ (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
+ }
+
+ }
+ else{
+ /* Call the callback function*/
+ toUnicodeCallback(args->converter,mySourceChar,targetUniChar,err);
+ break;
+ }
+ }
+ else{ /* goes with "if(myTarget < args->targetLimit)" way up near top of function */
+ *err =U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+endloop:
+ args->target = myTarget;
+ args->source = mySource;
+}
+
+
+/***************************************************************
+* Rules for ISO-2022-KR encoding
+* i) The KSC5601 designator sequence should appear only once in a file,
+* at the begining of a line before any KSC5601 characters. This usually
+* means that it appears by itself on the first line of the file
+* ii) There are only 2 shifting sequences SO to shift into double byte mode
+* and SI to shift into single byte mode
+*/
+static void
+UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(UConverterFromUnicodeArgs* args, UErrorCode* err){
+
+ UConverter* saveConv = args->converter;
+ UConverterDataISO2022 *myConverterData=(UConverterDataISO2022*)saveConv->extraInfo;
+ args->converter=myConverterData->currentConverter;
+
+ myConverterData->currentConverter->fromUChar32 = saveConv->fromUChar32;
+ ucnv_MBCSFromUnicodeWithOffsets(args,err);
+ saveConv->fromUChar32 = myConverterData->currentConverter->fromUChar32;
+
+ if(*err == U_BUFFER_OVERFLOW_ERROR) {
+ if(myConverterData->currentConverter->charErrorBufferLength > 0) {
+ uprv_memcpy(
+ saveConv->charErrorBuffer,
+ myConverterData->currentConverter->charErrorBuffer,
+ myConverterData->currentConverter->charErrorBufferLength);
+ }
+ saveConv->charErrorBufferLength = myConverterData->currentConverter->charErrorBufferLength;
+ myConverterData->currentConverter->charErrorBufferLength = 0;
+ }
+ args->converter=saveConv;
+}
+
+static void
+UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
+
+ const UChar *source = args->source;
+ const UChar *sourceLimit = args->sourceLimit;
+ unsigned char *target = (unsigned char *) args->target;
+ unsigned char *targetLimit = (unsigned char *) args->targetLimit;
+ int32_t* offsets = args->offsets;
+ uint32_t targetByteUnit = 0x0000;
+ UChar32 sourceChar = 0x0000;
+ UBool isTargetByteDBCS;
+ UBool oldIsTargetByteDBCS;
+ UConverterDataISO2022 *converterData;
+ UConverterSharedData* sharedData;
+ UBool useFallback;
+ int32_t length =0;
+
+ converterData=(UConverterDataISO2022*)args->converter->extraInfo;
+ /* if the version is 1 then the user is requesting
+ * conversion with ibm-25546 pass the arguments to
+ * MBCS converter and return
+ */
+ if(converterData->version==1){
+ UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(args,err);
+ return;
+ }
+
+ /* initialize data */
+ sharedData = converterData->currentConverter->sharedData;
+ useFallback = args->converter->useFallback;
+ isTargetByteDBCS=(UBool)args->converter->fromUnicodeStatus;
+ oldIsTargetByteDBCS = isTargetByteDBCS;
+
+ isTargetByteDBCS = (UBool) args->converter->fromUnicodeStatus;
+ if((sourceChar = args->converter->fromUChar32)!=0 && target targetLimit){
+ sourceChar = *source++;
+
+ /* do not convert SO/SI/ESC */
+ if(IS_2022_CONTROL(sourceChar)) {
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ args->converter->fromUChar32=sourceChar;
+ break;
+ }
+
+ length = MBCS_FROM_UCHAR32_ISO2022(sharedData,sourceChar,&targetByteUnit,useFallback,MBCS_OUTPUT_2);
+ if(length < 0) {
+ length = -length; /* fallback */
+ }
+ /* only DBCS or SBCS characters are expected*/
+ /* DB characters with high bit set to 1 are expected */
+ if(length > 2 || length==0 ||(((targetByteUnit & 0x8080) != 0x8080)&& length==2)){
+ targetByteUnit=missingCharMarker;
+ }
+ if (targetByteUnit != missingCharMarker){
+
+ oldIsTargetByteDBCS = isTargetByteDBCS;
+ isTargetByteDBCS = (UBool)(targetByteUnit>0x00FF);
+ /* append the shift sequence */
+ if (oldIsTargetByteDBCS != isTargetByteDBCS ){
+
+ if (isTargetByteDBCS)
+ *target++ = UCNV_SO;
+ else
+ *target++ = UCNV_SI;
+ if(offsets)
+ *(offsets++) = (int32_t)(source - args->source-1);
+ }
+ /* write the targetUniChar to target */
+ if(targetByteUnit <= 0x00FF){
+ if( target < targetLimit){
+ *(target++) = (unsigned char) targetByteUnit;
+ if(offsets){
+ *(offsets++) = (int32_t)(source - args->source-1);
+ }
+
+ }else{
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit);
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }else{
+ if(target < targetLimit){
+ *(target++) =(unsigned char) ((targetByteUnit>>8) -0x80);
+ if(offsets){
+ *(offsets++) = (int32_t)(source - args->source-1);
+ }
+ if(target < targetLimit){
+ *(target++) =(unsigned char) (targetByteUnit -0x80);
+ if(offsets){
+ *(offsets++) = (int32_t)(source - args->source-1);
+ }
+ }else{
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit -0x80);
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }else{
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) ((targetByteUnit>>8) -0x80);
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (unsigned char) (targetByteUnit-0x80);
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+
+ }
+ else{
+ /* oops.. the code point is unassingned
+ * set the error and reason
+ */
+
+ /*check if the char is a First surrogate*/
+ if(UTF_IS_SURROGATE(sourceChar)) {
+ if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
+getTrail:
+ /*look ahead to find the trail surrogate*/
+ if(source < sourceLimit) {
+ /* test the following code unit */
+ UChar trail=(UChar) *source;
+ if(UTF_IS_SECOND_SURROGATE(trail)) {
+ source++;
+ sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
+ *err = U_INVALID_CHAR_FOUND;
+ /* convert this surrogate code point */
+ /* exit this condition tree */
+ } else {
+ /* this is an unmatched lead code unit (1st surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* no more input */
+ *err = U_ZERO_ERROR;
+ }
+ } else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* callback(unassigned) for a BMP code point */
+ *err = U_INVALID_CHAR_FOUND;
+ }
+
+ args->converter->fromUChar32=sourceChar;
+ break;
+ }
+ } /* end if(myTargetIndexflush && source>=sourceLimit && args->converter->fromUChar32==0
+ ) {
+ int32_t sourceIndex;
+
+ /* we are switching to ASCII */
+ isTargetByteDBCS=FALSE;
+
+ /* get the source index of the last input character */
+ /*
+ * TODO this would be simpler and more reliable if we used a pair
+ * of sourceIndex/prevSourceIndex like in ucnvmbcs.c
+ * so that we could simply use the prevSourceIndex here;
+ * this code gives an incorrect result for the rare case of an unmatched
+ * trail surrogate that is alone in the last buffer of the text stream
+ */
+ sourceIndex=(int32_t)(source-args->source);
+ if(sourceIndex>0) {
+ --sourceIndex;
+ if( U16_IS_TRAIL(args->source[sourceIndex]) &&
+ (sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
+ ) {
+ --sourceIndex;
+ }
+ } else {
+ sourceIndex=-1;
+ }
+
+ fromUWriteUInt8(
+ args->converter,
+ SHIFT_IN_STR, 1,
+ &target, (const char *)targetLimit,
+ &offsets, sourceIndex,
+ err);
+ }
+
+ /*save the state and return */
+ args->source = source;
+ args->target = (char*)target;
+ args->converter->fromUnicodeStatus = (uint32_t)isTargetByteDBCS;
+}
+
+/************************ To Unicode ***************************************/
+
+static void
+UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(UConverterToUnicodeArgs *args,
+ UErrorCode* err){
+ char const* sourceStart;
+ UConverterDataISO2022* myData=(UConverterDataISO2022*)(args->converter->extraInfo);
+
+ UConverterToUnicodeArgs subArgs;
+ int32_t minArgsSize;
+
+ /* set up the subconverter arguments */
+ if(args->sizesize;
+ } else {
+ minArgsSize = (int32_t)sizeof(UConverterToUnicodeArgs);
+ }
+
+ uprv_memcpy(&subArgs, args, minArgsSize);
+ subArgs.size = (uint16_t)minArgsSize;
+ subArgs.converter = myData->currentConverter;
+
+ /* remember the original start of the input for offsets */
+ sourceStart = args->source;
+
+ if(myData->key != 0) {
+ /* continue with a partial escape sequence */
+ goto escape;
+ }
+
+ while(U_SUCCESS(*err) && args->source < args->sourceLimit) {
+ /*Find the end of the buffer e.g : Next Escape Seq | end of Buffer*/
+ subArgs.source = args->source;
+ subArgs.sourceLimit = getEndOfBuffer_2022(&(args->source), args->sourceLimit, args->flush);
+ if(subArgs.source != subArgs.sourceLimit) {
+ /*
+ * get the current partial byte sequence
+ *
+ * it needs to be moved between the public and the subconverter
+ * so that the conversion framework, which only sees the public
+ * converter, can handle truncated and illegal input etc.
+ */
+ if(args->converter->toULength > 0) {
+ uprv_memcpy(subArgs.converter->toUBytes, args->converter->toUBytes, args->converter->toULength);
+ }
+ subArgs.converter->toULength = args->converter->toULength;
+
+ /*
+ * Convert up to the end of the input, or to before the next escape character.
+ * Does not handle conversion extensions because the preToU[] state etc.
+ * is not copied.
+ */
+ ucnv_MBCSToUnicodeWithOffsets(&subArgs, err);
+
+ if(args->offsets != NULL && sourceStart != args->source) {
+ /* update offsets to base them on the actual start of the input */
+ int32_t *offsets = args->offsets;
+ UChar *target = args->target;
+ int32_t delta = (int32_t)(args->source - sourceStart);
+ while(target < subArgs.target) {
+ if(*offsets >= 0) {
+ *offsets += delta;
+ }
+ ++offsets;
+ ++target;
+ }
+ }
+ args->source = subArgs.source;
+ args->target = subArgs.target;
+ args->offsets = subArgs.offsets;
+
+ /* copy input/error/overflow buffers */
+ if(subArgs.converter->toULength > 0) {
+ uprv_memcpy(args->converter->toUBytes, subArgs.converter->toUBytes, subArgs.converter->toULength);
+ }
+ args->converter->toULength = subArgs.converter->toULength;
+
+ if(*err == U_BUFFER_OVERFLOW_ERROR) {
+ if(subArgs.converter->UCharErrorBufferLength > 0) {
+ uprv_memcpy(args->converter->UCharErrorBuffer, subArgs.converter->UCharErrorBuffer,
+ subArgs.converter->UCharErrorBufferLength);
+ }
+ args->converter->UCharErrorBufferLength=subArgs.converter->UCharErrorBufferLength;
+ subArgs.converter->UCharErrorBufferLength = 0;
+ }
+ }
+
+ if (U_FAILURE(*err) || (args->source == args->sourceLimit)) {
+ return;
+ }
+
+escape:
+ changeState_2022(args->converter,
+ &(args->source),
+ args->sourceLimit,
+ ISO_2022_KR,
+ err);
+ }
+}
+
+static void
+UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
+ UErrorCode* err){
+ char tempBuf[2];
+ const char *mySource = ( char *) args->source;
+ UChar *myTarget = args->target;
+ const char *mySourceLimit = args->sourceLimit;
+ UChar32 targetUniChar = 0x0000;
+ UChar mySourceChar = 0x0000;
+ UConverterDataISO2022* myData;
+ UConverterSharedData* sharedData ;
+ UBool useFallback;
+
+ myData=(UConverterDataISO2022*)(args->converter->extraInfo);
+ if(myData->version==1){
+ UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC_IBM(args,err);
+ return;
+ }
+
+ /* initialize state */
+ sharedData = myData->currentConverter->sharedData;
+ useFallback = args->converter->useFallback;
+
+ if(myData->key != 0) {
+ /* continue with a partial escape sequence */
+ goto escape;
+ } else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
+ /* continue with a partial double-byte character */
+ mySourceChar = args->converter->toUBytes[0];
+ args->converter->toULength = 0;
+ goto getTrailByte;
+ }
+
+ while(mySource< mySourceLimit){
+
+ if(myTarget < args->targetLimit){
+
+ mySourceChar= (unsigned char) *mySource++;
+
+ if(mySourceChar==UCNV_SI){
+ myData->toU2022State.g = 0;
+ /*consume the source */
+ continue;
+ }else if(mySourceChar==UCNV_SO){
+ myData->toU2022State.g = 1;
+ /*consume the source */
+ continue;
+ }else if(mySourceChar==ESC_2022){
+ mySource--;
+escape:
+ changeState_2022(args->converter,&(mySource),
+ mySourceLimit, ISO_2022_KR, err);
+ if(U_FAILURE(*err)){
+ args->target = myTarget;
+ args->source = mySource;
+ return;
+ }
+ continue;
+ }
+
+ if(myData->toU2022State.g == 1) {
+ if(mySource < mySourceLimit) {
+ char trailByte;
+getTrailByte:
+ trailByte = *mySource++;
+ tempBuf[0] = (char)(mySourceChar + 0x80);
+ tempBuf[1] = (char)(trailByte + 0x80);
+ mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
+ if((mySourceChar & 0x8080) == 0) {
+ targetUniChar = ucnv_MBCSSimpleGetNextUChar(sharedData, tempBuf, 2, useFallback);
+ } else {
+ /* illegal bytes > 0x7f */
+ targetUniChar = missingCharMarker;
+ }
+ } else {
+ args->converter->toUBytes[0] = (uint8_t)mySourceChar;
+ args->converter->toULength = 1;
+ break;
+ }
+ }
+ else{
+ targetUniChar = ucnv_MBCSSimpleGetNextUChar(sharedData, mySource - 1, 1, useFallback);
+ }
+ if(targetUniChar < 0xfffe){
+ if(args->offsets) {
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ *(myTarget++)=(UChar)targetUniChar;
+ }
+ else {
+ /* Call the callback function*/
+ toUnicodeCallback(args->converter,mySourceChar,targetUniChar,err);
+ break;
+ }
+ }
+ else{
+ *err =U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ args->target = myTarget;
+ args->source = mySource;
+}
+
+/*************************** END ISO2022-KR *********************************/
+
+/*************************** ISO-2022-CN *********************************
+*
+* Rules for ISO-2022-CN Encoding:
+* i) The designator sequence must appear once on a line before any instance
+* of character set it designates.
+* ii) If two lines contain characters from the same character set, both lines
+* must include the designator sequence.
+* iii) Once the designator sequence is known, a shifting sequence has to be found
+* to invoke the shifting
+* iv) All lines start in ASCII and end in ASCII.
+* v) Four shifting sequences are employed for this purpose:
+*
+* Sequcence ASCII Eq Charsets
+* ---------- ------- ---------
+* SI US-ASCII
+* SO CNS-11643-1992 Plane 1, GB2312, ISO-IR-165
+* SS2 N CNS-11643-1992 Plane 2
+* SS3 O CNS-11643-1992 Planes 3-7
+*
+* vi)
+* SOdesignator : ESC "$" ")" finalchar_for_SO
+* SS2designator : ESC "$" "*" finalchar_for_SS2
+* SS3designator : ESC "$" "+" finalchar_for_SS3
+*
+* ESC $ ) A Indicates the bytes following SO are Chinese
+* characters as defined in GB 2312-80, until
+* another SOdesignation appears
+*
+*
+* ESC $ ) E Indicates the bytes following SO are as defined
+* in ISO-IR-165 (for details, see section 2.1),
+* until another SOdesignation appears
+*
+* ESC $ ) G Indicates the bytes following SO are as defined
+* in CNS 11643-plane-1, until another
+* SOdesignation appears
+*
+* ESC $ * H Indicates the two bytes immediately following
+* SS2 is a Chinese character as defined in CNS
+* 11643-plane-2, until another SS2designation
+* appears
+* (Meaning N must preceed every 2 byte
+* sequence.)
+*
+* ESC $ + I Indicates the immediate two bytes following SS3
+* is a Chinese character as defined in CNS
+* 11643-plane-3, until another SS3designation
+* appears
+* (Meaning O must preceed every 2 byte
+* sequence.)
+*
+* ESC $ + J Indicates the immediate two bytes following SS3
+* is a Chinese character as defined in CNS
+* 11643-plane-4, until another SS3designation
+* appears
+* (In English: O must preceed every 2 byte
+* sequence.)
+*
+* ESC $ + K Indicates the immediate two bytes following SS3
+* is a Chinese character as defined in CNS
+* 11643-plane-5, until another SS3designation
+* appears
+*
+* ESC $ + L Indicates the immediate two bytes following SS3
+* is a Chinese character as defined in CNS
+* 11643-plane-6, until another SS3designation
+* appears
+*
+* ESC $ + M Indicates the immediate two bytes following SS3
+* is a Chinese character as defined in CNS
+* 11643-plane-7, until another SS3designation
+* appears
+*
+* As in ISO-2022-CN, each line starts in ASCII, and ends in ASCII, and
+* has its own designation information before any Chinese characters
+* appear
+*
+*/
+
+/* The following are defined this way to make the strings truely readonly */
+static const char GB_2312_80_STR[] = "\x1B\x24\x29\x41";
+static const char ISO_IR_165_STR[] = "\x1B\x24\x29\x45";
+static const char CNS_11643_1992_Plane_1_STR[] = "\x1B\x24\x29\x47";
+static const char CNS_11643_1992_Plane_2_STR[] = "\x1B\x24\x2A\x48";
+static const char CNS_11643_1992_Plane_3_STR[] = "\x1B\x24\x2B\x49";
+static const char CNS_11643_1992_Plane_4_STR[] = "\x1B\x24\x2B\x4A";
+static const char CNS_11643_1992_Plane_5_STR[] = "\x1B\x24\x2B\x4B";
+static const char CNS_11643_1992_Plane_6_STR[] = "\x1B\x24\x2B\x4C";
+static const char CNS_11643_1992_Plane_7_STR[] = "\x1B\x24\x2B\x4D";
+
+/********************** ISO2022-CN Data **************************/
+static const char* const escSeqCharsCN[10] ={
+ SHIFT_IN_STR, /* ASCII */
+ GB_2312_80_STR,
+ ISO_IR_165_STR,
+ CNS_11643_1992_Plane_1_STR,
+ CNS_11643_1992_Plane_2_STR,
+ CNS_11643_1992_Plane_3_STR,
+ CNS_11643_1992_Plane_4_STR,
+ CNS_11643_1992_Plane_5_STR,
+ CNS_11643_1992_Plane_6_STR,
+ CNS_11643_1992_Plane_7_STR
+};
+
+static void
+UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterFromUnicodeArgs* args, UErrorCode* err){
+ UConverter *cnv = args->converter;
+ UConverterDataISO2022 *converterData;
+ ISO2022State *pFromU2022State;
+ uint8_t *target = (uint8_t *) args->target;
+ const uint8_t *targetLimit = (const uint8_t *) args->targetLimit;
+ const UChar* source = args->source;
+ const UChar* sourceLimit = args->sourceLimit;
+ int32_t* offsets = args->offsets;
+ UChar32 sourceChar;
+ char buffer[8];
+ int32_t len;
+ int8_t choices[3];
+ int32_t choiceCount;
+ uint32_t targetValue = 0;
+ UBool useFallback;
+
+ /* set up the state */
+ converterData = (UConverterDataISO2022*)cnv->extraInfo;
+ pFromU2022State = &converterData->fromU2022State;
+
+ choiceCount = 0;
+
+ /* check if the last codepoint of previous buffer was a lead surrogate*/
+ if((sourceChar = cnv->fromUChar32)!=0 && target< targetLimit) {
+ goto getTrail;
+ }
+
+ while( source < sourceLimit){
+ if(target < targetLimit){
+
+ sourceChar = *(source++);
+ /*check if the char is a First surrogate*/
+ if(UTF_IS_SURROGATE(sourceChar)) {
+ if(UTF_IS_SURROGATE_FIRST(sourceChar)) {
+getTrail:
+ /*look ahead to find the trail surrogate*/
+ if(source < sourceLimit) {
+ /* test the following code unit */
+ UChar trail=(UChar) *source;
+ if(UTF_IS_SECOND_SURROGATE(trail)) {
+ source++;
+ sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail);
+ cnv->fromUChar32=0x00;
+ /* convert this supplementary code point */
+ /* exit this condition tree */
+ } else {
+ /* this is an unmatched lead code unit (1st surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ } else {
+ /* no more input */
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ } else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ }
+
+ /* do the conversion */
+ if(sourceChar <= 0x007f ){
+ /* do not convert SO/SI/ESC */
+ if(IS_2022_CONTROL(sourceChar)) {
+ /* callback(illegal) */
+ *err=U_ILLEGAL_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+
+ /* US-ASCII */
+ if(pFromU2022State->g == 0) {
+ buffer[0] = (char)sourceChar;
+ len = 1;
+ } else {
+ buffer[0] = UCNV_SI;
+ buffer[1] = (char)sourceChar;
+ len = 2;
+ pFromU2022State->g = 0;
+ choiceCount = 0;
+ }
+ if(sourceChar == CR || sourceChar == LF) {
+ /* reset the state at the end of a line */
+ uprv_memset(pFromU2022State, 0, sizeof(ISO2022State));
+ choiceCount = 0;
+ }
+ }
+ else{
+ /* convert U+0080..U+10ffff */
+ int32_t i;
+ int8_t cs, g;
+
+ if(choiceCount == 0) {
+ /* try the current SO/G1 converter first */
+ choices[0] = pFromU2022State->cs[1];
+
+ /* default to GB2312_1 if none is designated yet */
+ if(choices[0] == 0) {
+ choices[0] = GB2312_1;
+ }
+
+ if(converterData->version == 0) {
+ /* ISO-2022-CN */
+
+ /* try the other SO/G1 converter; a CNS_11643_1 lookup may result in any plane */
+ if(choices[0] == GB2312_1) {
+ choices[1] = (int8_t)CNS_11643_1;
+ } else {
+ choices[1] = (int8_t)GB2312_1;
+ }
+
+ choiceCount = 2;
+ } else {
+ /* ISO-2022-CN-EXT */
+
+ /* try one of the other converters */
+ switch(choices[0]) {
+ case GB2312_1:
+ choices[1] = (int8_t)CNS_11643_1;
+ choices[2] = (int8_t)ISO_IR_165;
+ break;
+ case ISO_IR_165:
+ choices[1] = (int8_t)GB2312_1;
+ choices[2] = (int8_t)CNS_11643_1;
+ break;
+ default: /* CNS_11643_x */
+ choices[1] = (int8_t)GB2312_1;
+ choices[2] = (int8_t)ISO_IR_165;
+ break;
+ }
+
+ choiceCount = 3;
+ }
+ }
+
+ cs = g = 0;
+ /*
+ * len==0: no mapping found yet
+ * len<0: found a fallback result: continue looking for a roundtrip but no further fallbacks
+ * len>0: found a roundtrip result, done
+ */
+ len = 0;
+ /*
+ * We will turn off useFallback after finding a fallback,
+ * but we still get fallbacks from PUA code points as usual.
+ * Therefore, we will also need to check that we don't overwrite
+ * an early fallback with a later one.
+ */
+ useFallback = cnv->useFallback;
+
+ for(i = 0; i < choiceCount && len <= 0; ++i) {
+ int8_t cs0 = choices[i];
+ if(cs0 > 0) {
+ uint32_t value;
+ int32_t len2;
+ if(cs0 > CNS_11643_0) {
+ len2 = MBCS_FROM_UCHAR32_ISO2022(
+ converterData->myConverterArray[CNS_11643],
+ sourceChar,
+ &value,
+ useFallback,
+ MBCS_OUTPUT_3);
+ if(len2 == 3 || (len2 == -3 && len == 0)) {
+ targetValue = value;
+ cs = (int8_t)(CNS_11643_0 + (value >> 16) - 0x80);
+ if(len2 >= 0) {
+ len = 2;
+ } else {
+ len = -2;
+ useFallback = FALSE;
+ }
+ if(cs == CNS_11643_1) {
+ g = 1;
+ } else if(cs == CNS_11643_2) {
+ g = 2;
+ } else /* plane 3..7 */ if(converterData->version == 1) {
+ g = 3;
+ } else {
+ /* ISO-2022-CN (without -EXT) does not support plane 3..7 */
+ len = 0;
+ }
+ }
+ } else {
+ /* GB2312_1 or ISO-IR-165 */
+ len2 = MBCS_FROM_UCHAR32_ISO2022(
+ converterData->myConverterArray[cs0],
+ sourceChar,
+ &value,
+ useFallback,
+ MBCS_OUTPUT_2);
+ if(len2 == 2 || (len2 == -2 && len == 0)) {
+ targetValue = value;
+ len = len2;
+ cs = cs0;
+ g = 1;
+ useFallback = FALSE;
+ }
+ }
+ }
+ }
+
+ if(len != 0) {
+ len = 0; /* count output bytes; it must have been abs(len) == 2 */
+
+ /* write the designation sequence if necessary */
+ if(cs != pFromU2022State->cs[g]) {
+ if(cs < CNS_11643) {
+ uprv_memcpy(buffer, escSeqCharsCN[cs], 4);
+ } else {
+ uprv_memcpy(buffer, escSeqCharsCN[CNS_11643 + (cs - CNS_11643_1)], 4);
+ }
+ len = 4;
+ pFromU2022State->cs[g] = cs;
+ if(g == 1) {
+ /* changing the SO/G1 charset invalidates the choices[] */
+ choiceCount = 0;
+ }
+ }
+
+ /* write the shift sequence if necessary */
+ if(g != pFromU2022State->g) {
+ switch(g) {
+ case 1:
+ buffer[len++] = UCNV_SO;
+
+ /* set the new state only if it is the locking shift SO/G1, not for SS2 or SS3 */
+ pFromU2022State->g = 1;
+ break;
+ case 2:
+ buffer[len++] = 0x1b;
+ buffer[len++] = 0x4e;
+ break;
+ default: /* case 3 */
+ buffer[len++] = 0x1b;
+ buffer[len++] = 0x4f;
+ break;
+ }
+ }
+
+ /* write the two output bytes */
+ buffer[len++] = (char)(targetValue >> 8);
+ buffer[len++] = (char)targetValue;
+ } else {
+ /* if we cannot find the character after checking all codepages
+ * then this is an error
+ */
+ *err = U_INVALID_CHAR_FOUND;
+ cnv->fromUChar32=sourceChar;
+ break;
+ }
+ }
+
+ /* output len>0 bytes in buffer[] */
+ if(len == 1) {
+ *target++ = buffer[0];
+ if(offsets) {
+ *offsets++ = (int32_t)(source - args->source - 1); /* -1: known to be ASCII */
+ }
+ } else if(len == 2 && (target + 2) <= targetLimit) {
+ *target++ = buffer[0];
+ *target++ = buffer[1];
+ if(offsets) {
+ int32_t sourceIndex = (int32_t)(source - args->source - U16_LENGTH(sourceChar));
+ *offsets++ = sourceIndex;
+ *offsets++ = sourceIndex;
+ }
+ } else {
+ fromUWriteUInt8(
+ cnv,
+ buffer, len,
+ &target, (const char *)targetLimit,
+ &offsets, (int32_t)(source - args->source - U16_LENGTH(sourceChar)),
+ err);
+ if(U_FAILURE(*err)) {
+ break;
+ }
+ }
+ } /* end if(myTargetIndexg!=0 &&
+ args->flush && source>=sourceLimit && cnv->fromUChar32==0
+ ) {
+ int32_t sourceIndex;
+
+ /* we are switching to ASCII */
+ pFromU2022State->g=0;
+
+ /* get the source index of the last input character */
+ /*
+ * TODO this would be simpler and more reliable if we used a pair
+ * of sourceIndex/prevSourceIndex like in ucnvmbcs.c
+ * so that we could simply use the prevSourceIndex here;
+ * this code gives an incorrect result for the rare case of an unmatched
+ * trail surrogate that is alone in the last buffer of the text stream
+ */
+ sourceIndex=(int32_t)(source-args->source);
+ if(sourceIndex>0) {
+ --sourceIndex;
+ if( U16_IS_TRAIL(args->source[sourceIndex]) &&
+ (sourceIndex==0 || U16_IS_LEAD(args->source[sourceIndex-1]))
+ ) {
+ --sourceIndex;
+ }
+ } else {
+ sourceIndex=-1;
+ }
+
+ fromUWriteUInt8(
+ cnv,
+ SHIFT_IN_STR, 1,
+ &target, (const char *)targetLimit,
+ &offsets, sourceIndex,
+ err);
+ }
+
+ /*save the state and return */
+ args->source = source;
+ args->target = (char*)target;
+}
+
+
+static void
+UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
+ UErrorCode* err){
+ char tempBuf[3];
+ const char *mySource = (char *) args->source;
+ UChar *myTarget = args->target;
+ const char *mySourceLimit = args->sourceLimit;
+ uint32_t targetUniChar = 0x0000;
+ uint32_t mySourceChar = 0x0000;
+ UConverterDataISO2022* myData;
+ ISO2022State *pToU2022State;
+
+ myData=(UConverterDataISO2022*)(args->converter->extraInfo);
+ pToU2022State = &myData->toU2022State;
+
+ if(myData->key != 0) {
+ /* continue with a partial escape sequence */
+ goto escape;
+ } else if(args->converter->toULength == 1 && mySource < mySourceLimit && myTarget < args->targetLimit) {
+ /* continue with a partial double-byte character */
+ mySourceChar = args->converter->toUBytes[0];
+ args->converter->toULength = 0;
+ goto getTrailByte;
+ }
+
+ while(mySource < mySourceLimit){
+
+ targetUniChar =missingCharMarker;
+
+ if(myTarget < args->targetLimit){
+
+ mySourceChar= (unsigned char) *mySource++;
+
+ switch(mySourceChar){
+ case UCNV_SI:
+ pToU2022State->g=0;
+ continue;
+
+ case UCNV_SO:
+ if(pToU2022State->cs[1] != 0) {
+ pToU2022State->g=1;
+ continue;
+ } else {
+ /* illegal to have SO before a matching designator */
+ break;
+ }
+
+ case ESC_2022:
+ mySource--;
+escape:
+ changeState_2022(args->converter,&(mySource),
+ mySourceLimit, ISO_2022_CN,err);
+
+ /* invalid or illegal escape sequence */
+ if(U_FAILURE(*err)){
+ args->target = myTarget;
+ args->source = mySource;
+ return;
+ }
+ continue;
+
+ /* ISO-2022-CN does not use single-byte (C1) SS2 and SS3 */
+
+ case CR:
+ /*falls through*/
+ case LF:
+ uprv_memset(pToU2022State, 0, sizeof(ISO2022State));
+ /* falls through */
+ default:
+ /* convert one or two bytes */
+ if(pToU2022State->g != 0) {
+ if(mySource < mySourceLimit) {
+ UConverterSharedData *cnv;
+ StateEnum tempState;
+ int32_t tempBufLen;
+ char trailByte;
+getTrailByte:
+ trailByte = *mySource++;
+ tempState = (StateEnum)pToU2022State->cs[pToU2022State->g];
+ if(tempState > CNS_11643_0) {
+ cnv = myData->myConverterArray[CNS_11643];
+ tempBuf[0] = (char) (0x80+(tempState-CNS_11643_0));
+ tempBuf[1] = (char) (mySourceChar);
+ tempBuf[2] = trailByte;
+ tempBufLen = 3;
+
+ }else{
+ cnv = myData->myConverterArray[tempState];
+ tempBuf[0] = (char) (mySourceChar);
+ tempBuf[1] = trailByte;
+ tempBufLen = 2;
+ }
+ mySourceChar = (mySourceChar << 8) | (uint8_t)(trailByte);
+ if(pToU2022State->g>=2) {
+ /* return from a single-shift state to the previous one */
+ pToU2022State->g=pToU2022State->prevG;
+ }
+ targetUniChar = ucnv_MBCSSimpleGetNextUChar(cnv, tempBuf, tempBufLen, FALSE);
+ } else {
+ args->converter->toUBytes[0] = (uint8_t)mySourceChar;
+ args->converter->toULength = 1;
+ goto endloop;
+ }
+ }
+ else{
+ if(mySourceChar <= 0x7f) {
+ targetUniChar = (UChar) mySourceChar;
+ }
+ }
+ break;
+ }
+ if(targetUniChar < (missingCharMarker-1/*0xfffe*/)){
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ *(myTarget++)=(UChar)targetUniChar;
+ }
+ else if(targetUniChar > missingCharMarker){
+ /* disassemble the surrogate pair and write to output*/
+ targetUniChar-=0x0010000;
+ *myTarget = (UChar)(0xd800+(UChar)(targetUniChar>>10));
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ ++myTarget;
+ if(myTarget< args->targetLimit){
+ *myTarget = (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
+ if(args->offsets){
+ args->offsets[myTarget - args->target] = (int32_t)(mySource - args->source - (mySourceChar <= 0xff ? 1 : 2));
+ }
+ ++myTarget;
+ }else{
+ args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++]=
+ (UChar)(0xdc00+(UChar)(targetUniChar&0x3ff));
+ }
+
+ }
+ else{
+ /* Call the callback function*/
+ toUnicodeCallback(args->converter,mySourceChar,targetUniChar,err);
+ break;
+ }
+ }
+ else{
+ *err =U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+endloop:
+ args->target = myTarget;
+ args->source = mySource;
+}
+
+static void
+_ISO_2022_WriteSub(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode *err) {
+ UConverter *cnv = args->converter;
+ UConverterDataISO2022 *myConverterData=(UConverterDataISO2022 *) cnv->extraInfo;
+ ISO2022State *pFromU2022State=&myConverterData->fromU2022State;
+ char *p, *subchar;
+ char buffer[8];
+ int32_t length;
+
+ subchar=(char *)cnv->subChars;
+ length=cnv->subCharLen; /* assume length==1 for most variants */
+
+ p = buffer;
+ switch(myConverterData->locale[0]){
+ case 'j':
+ {
+ int8_t cs;
+
+ if(pFromU2022State->g == 1) {
+ /* JIS7: switch from G1 to G0 */
+ pFromU2022State->g = 0;
+ *p++ = UCNV_SI;
+ }
+
+ cs = pFromU2022State->cs[0];
+ if(cs != ASCII && cs != JISX201) {
+ /* not in ASCII or JIS X 0201: switch to ASCII */
+ pFromU2022State->cs[0] = (int8_t)ASCII;
+ *p++ = '\x1b';
+ *p++ = '\x28';
+ *p++ = '\x42';
+ }
+
+ *p++ = subchar[0];
+ break;
+ }
+ case 'c':
+ if(pFromU2022State->g != 0) {
+ /* not in ASCII mode: switch to ASCII */
+ pFromU2022State->g = 0;
+ *p++ = UCNV_SI;
+ }
+ *p++ = subchar[0];
+ break;
+ case 'k':
+ if(myConverterData->version == 0) {
+ if(length == 1) {
+ if((UBool)args->converter->fromUnicodeStatus) {
+ /* in DBCS mode: switch to SBCS */
+ args->converter->fromUnicodeStatus = 0;
+ *p++ = UCNV_SI;
+ }
+ *p++ = subchar[0];
+ } else /* length == 2*/ {
+ if(!(UBool)args->converter->fromUnicodeStatus) {
+ /* in SBCS mode: switch to DBCS */
+ args->converter->fromUnicodeStatus = 1;
+ *p++ = UCNV_SO;
+ }
+ *p++ = subchar[0];
+ *p++ = subchar[1];
+ }
+ break;
+ } else {
+ /* save the subconverter's substitution string */
+ uint8_t *currentSubChars = myConverterData->currentConverter->subChars;
+ int8_t currentSubCharLen = myConverterData->currentConverter->subCharLen;
+
+ /* set our substitution string into the subconverter */
+ myConverterData->currentConverter->subChars = (uint8_t *)subchar;
+ myConverterData->currentConverter->subCharLen = (int8_t)length;
+
+ /* let the subconverter write the subchar, set/retrieve fromUChar32 state */
+ args->converter = myConverterData->currentConverter;
+ myConverterData->currentConverter->fromUChar32 = cnv->fromUChar32;
+ ucnv_cbFromUWriteSub(args, 0, err);
+ cnv->fromUChar32 = myConverterData->currentConverter->fromUChar32;
+ args->converter = cnv;
+
+ /* restore the subconverter's substitution string */
+ myConverterData->currentConverter->subChars = currentSubChars;
+ myConverterData->currentConverter->subCharLen = currentSubCharLen;
+
+ if(*err == U_BUFFER_OVERFLOW_ERROR) {
+ if(myConverterData->currentConverter->charErrorBufferLength > 0) {
+ uprv_memcpy(
+ cnv->charErrorBuffer,
+ myConverterData->currentConverter->charErrorBuffer,
+ myConverterData->currentConverter->charErrorBufferLength);
+ }
+ cnv->charErrorBufferLength = myConverterData->currentConverter->charErrorBufferLength;
+ myConverterData->currentConverter->charErrorBufferLength = 0;
+ }
+ return;
+ }
+ default:
+ /* not expected */
+ break;
+ }
+ ucnv_cbFromUWriteBytes(args,
+ buffer, (int32_t)(p - buffer),
+ offsetIndex, err);
+}
+
+/*
+ * Structure for cloning an ISO 2022 converter into a single memory block.
+ * ucnv_safeClone() of the converter will align the entire cloneStruct,
+ * and then ucnv_safeClone() of the sub-converter may additionally align
+ * currentConverter inside the cloneStruct, for which we need the deadSpace
+ * after currentConverter.
+ * This is because UAlignedMemory may be larger than the actually
+ * necessary alignment size for the platform.
+ * The other cloneStruct fields will not be moved around,
+ * and are aligned properly with cloneStruct's alignment.
+ */
+struct cloneStruct
+{
+ UConverter cnv;
+ UConverter currentConverter;
+ UAlignedMemory deadSpace;
+ UConverterDataISO2022 mydata;
+};
+
+
+static UConverter *
+_ISO_2022_SafeClone(
+ const UConverter *cnv,
+ void *stackBuffer,
+ int32_t *pBufferSize,
+ UErrorCode *status)
+{
+ struct cloneStruct * localClone;
+ UConverterDataISO2022 *cnvData;
+ int32_t i, size;
+
+ if (*pBufferSize == 0) { /* 'preflighting' request - set needed size into *pBufferSize */
+ *pBufferSize = (int32_t)sizeof(struct cloneStruct);
+ return NULL;
+ }
+
+ cnvData = (UConverterDataISO2022 *)cnv->extraInfo;
+ localClone = (struct cloneStruct *)stackBuffer;
+
+ /* ucnv.c/ucnv_safeClone() copied the main UConverter already */
+
+ uprv_memcpy(&localClone->mydata, cnvData, sizeof(UConverterDataISO2022));
+ localClone->cnv.extraInfo = &localClone->mydata; /* set pointer to extra data */
+ localClone->cnv.isExtraLocal = TRUE;
+
+ /* share the subconverters */
+
+ if(cnvData->currentConverter != NULL) {
+ size = (int32_t)(sizeof(UConverter) + sizeof(UAlignedMemory)); /* include size of padding */
+ localClone->mydata.currentConverter =
+ ucnv_safeClone(cnvData->currentConverter,
+ &localClone->currentConverter,
+ &size, status);
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+ }
+
+ for(i=0; imyConverterArray[i] != NULL) {
+ ucnv_incrementRefCount(cnvData->myConverterArray[i]);
+ }
+ }
+
+ return &localClone->cnv;
+}
+
+static void
+_ISO_2022_GetUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode)
+{
+ int32_t i;
+ UConverterDataISO2022* cnvData;
+
+ if (U_FAILURE(*pErrorCode)) {
+ return;
+ }
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ if (cnv->sharedData == &_ISO2022Data) {
+ /* We use UTF-8 in this case */
+ sa->addRange(sa->set, 0, 0xd7FF);
+ sa->addRange(sa->set, 0xE000, 0x10FFFF);
+ return;
+ }
+#endif
+
+ cnvData = (UConverterDataISO2022*)cnv->extraInfo;
+
+ /* open a set and initialize it with code points that are algorithmically round-tripped */
+ switch(cnvData->locale[0]){
+ case 'j':
+ if(jpCharsetMasks[cnvData->version]&CSM(ISO8859_1)) {
+ /* include Latin-1 for some variants of JP */
+ sa->addRange(sa->set, 0, 0xff);
+ } else {
+ /* include ASCII for JP */
+ sa->addRange(sa->set, 0, 0x7f);
+ }
+ if(jpCharsetMasks[cnvData->version]&CSM(HWKANA_7BIT)) {
+ /* include half-width Katakana for JP */
+ sa->addRange(sa->set, HWKANA_START, HWKANA_END);
+ }
+ break;
+ case 'c':
+ case 'z':
+ /* include ASCII for CN */
+ sa->addRange(sa->set, 0, 0x7f);
+ break;
+ case 'k':
+ /* there is only one converter for KR, and it is not in the myConverterArray[] */
+ cnvData->currentConverter->sharedData->impl->getUnicodeSet(
+ cnvData->currentConverter, sa, which, pErrorCode);
+ /* the loop over myConverterArray[] will simply not find another converter */
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * Version-specific for CN:
+ * CN version 0 does not map CNS planes 3..7 although
+ * they are all available in the CNS conversion table;
+ * CN version 1 does map them all.
+ * The two versions create different Unicode sets.
+ */
+ for (i=0; imyConverterArray[i]!=NULL) {
+ if( (cnvData->locale[0]=='c' || cnvData->locale[0]=='z') &&
+ cnvData->version==0 && i==CNS_11643
+ ) {
+ /* special handling for non-EXT ISO-2022-CN: add only code points for CNS planes 1 and 2 */
+ ucnv_MBCSGetUnicodeSetForBytes(
+ cnvData->myConverterArray[i],
+ sa, UCNV_ROUNDTRIP_SET,
+ 0, 0x81, 0x82,
+ pErrorCode);
+ } else {
+ ucnv_MBCSGetUnicodeSetForUnicode(cnvData->myConverterArray[i], sa, which, pErrorCode);
+ }
+ }
+ }
+
+ /*
+ * ISO 2022 converters must not convert SO/SI/ESC despite what
+ * sub-converters do by themselves.
+ * Remove these characters from the set.
+ */
+ sa->remove(sa->set, 0x0e);
+ sa->remove(sa->set, 0x0f);
+ sa->remove(sa->set, 0x1b);
+}
+
+static const UConverterImpl _ISO2022Impl={
+ UCNV_ISO_2022,
+
+ NULL,
+ NULL,
+
+ _ISO2022Open,
+ _ISO2022Close,
+ _ISO2022Reset,
+
+#ifdef U_ENABLE_GENERIC_ISO_2022
+ T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC,
+ T_UConverter_toUnicode_ISO_2022_OFFSETS_LOGIC,
+ ucnv_fromUnicode_UTF8,
+ ucnv_fromUnicode_UTF8_OFFSETS_LOGIC,
+#else
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+#endif
+ NULL,
+
+ NULL,
+ _ISO2022getName,
+ _ISO_2022_WriteSub,
+ _ISO_2022_SafeClone,
+ _ISO_2022_GetUnicodeSet
+};
+static const UConverterStaticData _ISO2022StaticData={
+ sizeof(UConverterStaticData),
+ "ISO_2022",
+ 2022,
+ UCNV_IBM,
+ UCNV_ISO_2022,
+ 1,
+ 3, /* max 3 bytes per UChar from UTF-8 (4 bytes from surrogate _pair_) */
+ { 0x1a, 0, 0, 0 },
+ 1,
+ FALSE,
+ FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+const UConverterSharedData _ISO2022Data={
+ sizeof(UConverterSharedData),
+ ~((uint32_t) 0),
+ NULL,
+ NULL,
+ &_ISO2022StaticData,
+ FALSE,
+ &_ISO2022Impl,
+ 0
+};
+
+/*************JP****************/
+static const UConverterImpl _ISO2022JPImpl={
+ UCNV_ISO_2022,
+
+ NULL,
+ NULL,
+
+ _ISO2022Open,
+ _ISO2022Close,
+ _ISO2022Reset,
+
+ UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC,
+ UConverter_toUnicode_ISO_2022_JP_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_JP_OFFSETS_LOGIC,
+ NULL,
+
+ NULL,
+ _ISO2022getName,
+ _ISO_2022_WriteSub,
+ _ISO_2022_SafeClone,
+ _ISO_2022_GetUnicodeSet
+};
+static const UConverterStaticData _ISO2022JPStaticData={
+ sizeof(UConverterStaticData),
+ "ISO_2022_JP",
+ 0,
+ UCNV_IBM,
+ UCNV_ISO_2022,
+ 1,
+ 6, /* max 6 bytes per UChar: 4-byte escape sequence + DBCS */
+ { 0x1a, 0, 0, 0 },
+ 1,
+ FALSE,
+ FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+static const UConverterSharedData _ISO2022JPData={
+ sizeof(UConverterSharedData),
+ ~((uint32_t) 0),
+ NULL,
+ NULL,
+ &_ISO2022JPStaticData,
+ FALSE,
+ &_ISO2022JPImpl,
+ 0
+};
+
+/************* KR ***************/
+static const UConverterImpl _ISO2022KRImpl={
+ UCNV_ISO_2022,
+
+ NULL,
+ NULL,
+
+ _ISO2022Open,
+ _ISO2022Close,
+ _ISO2022Reset,
+
+ UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC,
+ UConverter_toUnicode_ISO_2022_KR_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_KR_OFFSETS_LOGIC,
+ NULL,
+
+ NULL,
+ _ISO2022getName,
+ _ISO_2022_WriteSub,
+ _ISO_2022_SafeClone,
+ _ISO_2022_GetUnicodeSet
+};
+static const UConverterStaticData _ISO2022KRStaticData={
+ sizeof(UConverterStaticData),
+ "ISO_2022_KR",
+ 0,
+ UCNV_IBM,
+ UCNV_ISO_2022,
+ 1,
+ 3, /* max 3 bytes per UChar: SO+DBCS */
+ { 0x1a, 0, 0, 0 },
+ 1,
+ FALSE,
+ FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+static const UConverterSharedData _ISO2022KRData={
+ sizeof(UConverterSharedData),
+ ~((uint32_t) 0),
+ NULL,
+ NULL,
+ &_ISO2022KRStaticData,
+ FALSE,
+ &_ISO2022KRImpl,
+ 0
+};
+
+/*************** CN ***************/
+static const UConverterImpl _ISO2022CNImpl={
+
+ UCNV_ISO_2022,
+
+ NULL,
+ NULL,
+
+ _ISO2022Open,
+ _ISO2022Close,
+ _ISO2022Reset,
+
+ UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC,
+ UConverter_toUnicode_ISO_2022_CN_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC,
+ UConverter_fromUnicode_ISO_2022_CN_OFFSETS_LOGIC,
+ NULL,
+
+ NULL,
+ _ISO2022getName,
+ _ISO_2022_WriteSub,
+ _ISO_2022_SafeClone,
+ _ISO_2022_GetUnicodeSet
+};
+static const UConverterStaticData _ISO2022CNStaticData={
+ sizeof(UConverterStaticData),
+ "ISO_2022_CN",
+ 0,
+ UCNV_IBM,
+ UCNV_ISO_2022,
+ 1,
+ 8, /* max 8 bytes per UChar: 4-byte CNS designator + 2 bytes for SS2/SS3 + DBCS */
+ { 0x1a, 0, 0, 0 },
+ 1,
+ FALSE,
+ FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+static const UConverterSharedData _ISO2022CNData={
+ sizeof(UConverterSharedData),
+ ~((uint32_t) 0),
+ NULL,
+ NULL,
+ &_ISO2022CNStaticData,
+ FALSE,
+ &_ISO2022CNImpl,
+ 0
+};
+
+
+
+#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_bld.c b/Build/source/libs/icu/icu-xetex/common/ucnv_bld.c
new file mode 100644
index 00000000000..f627d6b8239
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_bld.c
@@ -0,0 +1,1583 @@
+/*
+ ********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1996-2007, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************
+ *
+ * uconv_bld.c:
+ *
+ * Defines functions that are used in the creation/initialization/deletion
+ * of converters and related structures.
+ * uses uconv_io.h routines to access disk information
+ * is used by ucnv.h to implement public API create/delete/flushCache routines
+ * Modification History:
+ *
+ * Date Name Description
+ *
+ * 06/20/2000 helena OS/400 port changes; mostly typecast.
+ * 06/29/2000 helena Major rewrite of the callback interface.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/putil.h"
+#include "unicode/udata.h"
+#include "unicode/ucnv.h"
+#include "unicode/uloc.h"
+#include "utracimp.h"
+#include "ucnv_io.h"
+#include "ucnv_bld.h"
+#include "ucnvmbcs.h"
+#include "ucnv_ext.h"
+#include "ucnv_cnv.h"
+#include "ucnv_imp.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "ucln_cmn.h"
+#include "ustr_cnv.h"
+
+
+
+#if 0
+#include
+extern void UCNV_DEBUG_LOG(char *what, char *who, void *p, int l);
+#define UCNV_DEBUG_LOG(x,y,z) UCNV_DEBUG_LOG(x,y,z,__LINE__)
+#else
+# define UCNV_DEBUG_LOG(x,y,z)
+#endif
+
+static const UConverterSharedData * const
+converterData[UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES]={
+ NULL, NULL,
+
+#if UCONFIG_NO_LEGACY_CONVERSION
+ NULL,
+#else
+ &_MBCSData,
+#endif
+
+ &_Latin1Data,
+ &_UTF8Data, &_UTF16BEData, &_UTF16LEData, &_UTF32BEData, &_UTF32LEData,
+ NULL,
+
+#if UCONFIG_NO_LEGACY_CONVERSION
+ NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL,
+#else
+ &_ISO2022Data,
+ &_LMBCSData1,&_LMBCSData2, &_LMBCSData3, &_LMBCSData4, &_LMBCSData5, &_LMBCSData6,
+ &_LMBCSData8,&_LMBCSData11,&_LMBCSData16,&_LMBCSData17,&_LMBCSData18,&_LMBCSData19,
+ &_HZData,
+#endif
+
+ &_SCSUData,
+
+#if UCONFIG_NO_LEGACY_CONVERSION
+ NULL,
+#else
+ &_ISCIIData,
+#endif
+
+ &_ASCIIData,
+ &_UTF7Data, &_Bocu1Data, &_UTF16Data, &_UTF32Data, &_CESU8Data, &_IMAPData
+};
+
+/* Please keep this in binary sorted order for getAlgorithmicTypeFromName.
+ Also the name should be in lower case and all spaces, dashes and underscores
+ removed
+*/
+static struct {
+ const char *name;
+ const UConverterType type;
+} const cnvNameType[] = {
+ { "bocu1", UCNV_BOCU1 },
+ { "cesu8", UCNV_CESU8 },
+#if !UCONFIG_NO_LEGACY_CONVERSION
+ { "hz",UCNV_HZ },
+#endif
+ { "imapmailboxname", UCNV_IMAP_MAILBOX },
+#if !UCONFIG_NO_LEGACY_CONVERSION
+ { "iscii", UCNV_ISCII },
+ { "iso2022", UCNV_ISO_2022 },
+#endif
+ { "iso88591", UCNV_LATIN_1 },
+#if !UCONFIG_NO_LEGACY_CONVERSION
+ { "lmbcs1", UCNV_LMBCS_1 },
+ { "lmbcs11",UCNV_LMBCS_11 },
+ { "lmbcs16",UCNV_LMBCS_16 },
+ { "lmbcs17",UCNV_LMBCS_17 },
+ { "lmbcs18",UCNV_LMBCS_18 },
+ { "lmbcs19",UCNV_LMBCS_19 },
+ { "lmbcs2", UCNV_LMBCS_2 },
+ { "lmbcs3", UCNV_LMBCS_3 },
+ { "lmbcs4", UCNV_LMBCS_4 },
+ { "lmbcs5", UCNV_LMBCS_5 },
+ { "lmbcs6", UCNV_LMBCS_6 },
+ { "lmbcs8", UCNV_LMBCS_8 },
+#endif
+ { "scsu", UCNV_SCSU },
+ { "usascii", UCNV_US_ASCII },
+ { "utf16", UCNV_UTF16 },
+ { "utf16be", UCNV_UTF16_BigEndian },
+ { "utf16le", UCNV_UTF16_LittleEndian },
+#if U_IS_BIG_ENDIAN
+ { "utf16oppositeendian", UCNV_UTF16_LittleEndian },
+ { "utf16platformendian", UCNV_UTF16_BigEndian },
+#else
+ { "utf16oppositeendian", UCNV_UTF16_BigEndian},
+ { "utf16platformendian", UCNV_UTF16_LittleEndian },
+#endif
+ { "utf32", UCNV_UTF32 },
+ { "utf32be", UCNV_UTF32_BigEndian },
+ { "utf32le", UCNV_UTF32_LittleEndian },
+#if U_IS_BIG_ENDIAN
+ { "utf32oppositeendian", UCNV_UTF32_LittleEndian },
+ { "utf32platformendian", UCNV_UTF32_BigEndian },
+#else
+ { "utf32oppositeendian", UCNV_UTF32_BigEndian },
+ { "utf32platformendian", UCNV_UTF32_LittleEndian },
+#endif
+ { "utf7", UCNV_UTF7 },
+ { "utf8", UCNV_UTF8 }
+};
+
+
+/*initializes some global variables */
+static UHashtable *SHARED_DATA_HASHTABLE = NULL;
+static UMTX cnvCacheMutex = NULL; /* Mutex for synchronizing cnv cache access. */
+ /* Note: the global mutex is used for */
+ /* reference count updates. */
+
+static const char **gAvailableConverters = NULL;
+static uint16_t gAvailableConverterCount = 0;
+
+/* This contains the resolved converter name. So no further alias lookup is needed again. */
+static char gDefaultConverterNameBuffer[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; /* +1 for NULL */
+static const char *gDefaultConverterName = NULL;
+
+/*
+If the default converter is an algorithmic converter, this is the cached value.
+We don't cache a full UConverter and clone it because ucnv_clone doesn't have
+less overhead than an algorithmic open. We don't cache non-algorithmic converters
+because ucnv_flushCache must be able to unload the default converter and its table.
+*/
+static const UConverterSharedData *gDefaultAlgorithmicSharedData = NULL;
+
+/* Does gDefaultConverterName have a converter option and require extra parsing? */
+static UBool gDefaultConverterContainsOption;
+
+
+static const char DATA_TYPE[] = "cnv";
+
+/* ucnv_cleanup - delete all storage held by the converter cache, except any */
+/* in use by open converters. */
+/* Not thread safe. */
+/* Not supported API. */
+static UBool U_CALLCONV ucnv_cleanup(void) {
+ ucnv_flushCache();
+ if (SHARED_DATA_HASHTABLE != NULL && uhash_count(SHARED_DATA_HASHTABLE) == 0) {
+ uhash_close(SHARED_DATA_HASHTABLE);
+ SHARED_DATA_HASHTABLE = NULL;
+ }
+
+ /* Called from ucnv_flushCache because it allocates the hashtable */
+ /*ucnv_flushAvailableConverterCache();*/
+
+ gDefaultConverterName = NULL;
+ gDefaultConverterNameBuffer[0] = 0;
+ gDefaultConverterContainsOption = FALSE;
+ gDefaultAlgorithmicSharedData = NULL;
+
+ umtx_destroy(&cnvCacheMutex); /* Don't worry about destroying the mutex even */
+ /* if the hash table still exists. The mutex */
+ /* will lazily re-init itself if needed. */
+ return (SHARED_DATA_HASHTABLE == NULL);
+}
+
+static UBool U_CALLCONV
+isCnvAcceptable(void *context,
+ const char *type, const char *name,
+ const UDataInfo *pInfo) {
+ return (UBool)(
+ pInfo->size>=20 &&
+ pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
+ pInfo->charsetFamily==U_CHARSET_FAMILY &&
+ pInfo->sizeofUChar==U_SIZEOF_UCHAR &&
+ pInfo->dataFormat[0]==0x63 && /* dataFormat="cnvt" */
+ pInfo->dataFormat[1]==0x6e &&
+ pInfo->dataFormat[2]==0x76 &&
+ pInfo->dataFormat[3]==0x74 &&
+ pInfo->formatVersion[0]==6); /* Everything will be version 6 */
+}
+
+/**
+ * Un flatten shared data from a UDATA..
+ */
+static UConverterSharedData*
+ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCode *status)
+{
+ /* UDataInfo info; -- necessary only if some converters have different formatVersion */
+ const uint8_t *raw = (const uint8_t *)udata_getMemory(pData);
+ const UConverterStaticData *source = (const UConverterStaticData *) raw;
+ UConverterSharedData *data;
+ UConverterType type = (UConverterType)source->conversionType;
+
+ if(U_FAILURE(*status))
+ return NULL;
+
+ if( (uint16_t)type >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES ||
+ converterData[type] == NULL ||
+ converterData[type]->referenceCounter != 1 ||
+ source->structSize != sizeof(UConverterStaticData))
+ {
+ *status = U_INVALID_TABLE_FORMAT;
+ return NULL;
+ }
+
+ data = (UConverterSharedData *)uprv_malloc(sizeof(UConverterSharedData));
+ if(data == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ /* copy initial values from the static structure for this type */
+ uprv_memcpy(data, converterData[type], sizeof(UConverterSharedData));
+
+#if 0 /* made UConverterMBCSTable part of UConverterSharedData -- markus 20031107 */
+ /*
+ * It would be much more efficient if the table were a direct member, not a pointer.
+ * However, that would add to the size of all UConverterSharedData objects
+ * even if they do not use this table (especially algorithmic ones).
+ * If this changes, then the static templates from converterData[type]
+ * need more entries.
+ *
+ * In principle, it would be cleaner if the load() function below
+ * allocated the table.
+ */
+ data->table = (UConverterTable *)uprv_malloc(sizeof(UConverterTable));
+ if(data->table == NULL) {
+ uprv_free(data);
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memset(data->table, 0, sizeof(UConverterTable));
+#endif
+
+ data->staticData = source;
+
+ data->sharedDataCached = FALSE;
+
+ /* fill in fields from the loaded data */
+ data->dataMemory = (void*)pData; /* for future use */
+
+ if(data->impl->load != NULL) {
+ data->impl->load(data, pArgs, raw + source->structSize, status);
+ if(U_FAILURE(*status)) {
+ uprv_free(data->table);
+ uprv_free(data);
+ return NULL;
+ }
+ }
+ return data;
+}
+
+/*Takes an alias name gets an actual converter file name
+ *goes to disk and opens it.
+ *allocates the memory and returns a new UConverter object
+ */
+static UConverterSharedData *createConverterFromFile(UConverterLoadArgs *pArgs, UErrorCode * err)
+{
+ UDataMemory *data;
+ UConverterSharedData *sharedData;
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_LOAD);
+
+ if (U_FAILURE (*err)) {
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ UTRACE_DATA2(UTRACE_OPEN_CLOSE, "load converter %s from package %s", pArgs->name, pArgs->pkg);
+
+ data = udata_openChoice(pArgs->pkg, DATA_TYPE, pArgs->name, isCnvAcceptable, NULL, err);
+ if(U_FAILURE(*err))
+ {
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ sharedData = ucnv_data_unFlattenClone(pArgs, data, err);
+ if(U_FAILURE(*err))
+ {
+ udata_close(data);
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ /*
+ * TODO Store pkg in a field in the shared data so that delta-only converters
+ * can load base converters from the same package.
+ * If the pkg name is longer than the field, then either do not load the converter
+ * in the first place, or just set the pkg field to "".
+ */
+
+ UTRACE_EXIT_PTR_STATUS(sharedData, *err);
+ return sharedData;
+}
+
+/*returns a converter type from a string
+ */
+static const UConverterSharedData *
+getAlgorithmicTypeFromName(const char *realName)
+{
+ uint32_t mid, start, limit;
+ uint32_t lastMid;
+ int result;
+ char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH];
+
+ /* Lower case and remove ignoreable characters. */
+ ucnv_io_stripForCompare(strippedName, realName);
+
+ /* do a binary search for the alias */
+ start = 0;
+ limit = sizeof(cnvNameType)/sizeof(cnvNameType[0]);
+ mid = limit;
+ lastMid = UINT32_MAX;
+
+ for (;;) {
+ mid = (uint32_t)((start + limit) / 2);
+ if (lastMid == mid) { /* Have we moved? */
+ break; /* We haven't moved, and it wasn't found. */
+ }
+ lastMid = mid;
+ result = uprv_strcmp(strippedName, cnvNameType[mid].name);
+
+ if (result < 0) {
+ limit = mid;
+ } else if (result > 0) {
+ start = mid;
+ } else {
+ return converterData[cnvNameType[mid].type];
+ }
+ }
+
+ return NULL;
+}
+
+/*
+* Based on the number of known converters, this determines how many times larger
+* the shared data hash table should be. When on small platforms, or just a couple
+* of converters are used, this number should be 2. When memory is plentiful, or
+* when ucnv_countAvailable is ever used with a lot of available converters,
+* this should be 4.
+* Larger numbers reduce the number of hash collisions, but use more memory.
+*/
+#define UCNV_CACHE_LOAD_FACTOR 2
+
+/* Puts the shared data in the static hashtable SHARED_DATA_HASHTABLE */
+/* Will always be called with the cnvCacheMutex alrady being held */
+/* by the calling function. */
+/* Stores the shared data in the SHARED_DATA_HASHTABLE
+ * @param data The shared data
+ */
+static void
+ucnv_shareConverterData(UConverterSharedData * data)
+{
+ UErrorCode err = U_ZERO_ERROR;
+ /*Lazy evaluates the Hashtable itself */
+ /*void *sanity = NULL;*/
+
+ if (SHARED_DATA_HASHTABLE == NULL)
+ {
+ SHARED_DATA_HASHTABLE = uhash_openSize(uhash_hashChars, uhash_compareChars, NULL,
+ ucnv_io_countKnownConverters(&err)*UCNV_CACHE_LOAD_FACTOR,
+ &err);
+ ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
+
+ if (U_FAILURE(err))
+ return;
+ }
+
+ /* ### check to see if the element is not already there! */
+
+ /*
+ sanity = ucnv_getSharedConverterData (data->staticData->name);
+ if(sanity != NULL)
+ {
+ UCNV_DEBUG_LOG("put:overwrite!",data->staticData->name,sanity);
+ }
+ UCNV_DEBUG_LOG("put:chk",data->staticData->name,sanity);
+ */
+
+ /* Mark it shared */
+ data->sharedDataCached = TRUE;
+
+ uhash_put(SHARED_DATA_HASHTABLE,
+ (void*) data->staticData->name, /* Okay to cast away const as long as
+ keyDeleter == NULL */
+ data,
+ &err);
+ UCNV_DEBUG_LOG("put", data->staticData->name,data);
+
+}
+
+/* Look up a converter name in the shared data cache. */
+/* cnvCacheMutex must be held by the caller to protect the hash table. */
+/* gets the shared data from the SHARED_DATA_HASHTABLE (might return NULL if it isn't there)
+ * @param name The name of the shared data
+ * @return the shared data from the SHARED_DATA_HASHTABLE
+ */
+static UConverterSharedData *
+ucnv_getSharedConverterData(const char *name)
+{
+ /*special case when no Table has yet been created we return NULL */
+ if (SHARED_DATA_HASHTABLE == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ UConverterSharedData *rc;
+
+ rc = (UConverterSharedData*)uhash_get(SHARED_DATA_HASHTABLE, name);
+ UCNV_DEBUG_LOG("get",name,rc);
+ return rc;
+ }
+}
+
+/*frees the string of memory blocks associates with a sharedConverter
+ *if and only if the referenceCounter == 0
+ */
+/* Deletes (frees) the Shared data it's passed. first it checks the referenceCounter to
+ * see if anyone is using it, if not it frees all the memory stemming from sharedConverterData and
+ * returns TRUE,
+ * otherwise returns FALSE
+ * @param sharedConverterData The shared data
+ * @return if not it frees all the memory stemming from sharedConverterData and
+ * returns TRUE, otherwise returns FALSE
+ */
+static UBool
+ucnv_deleteSharedConverterData(UConverterSharedData * deadSharedData)
+{
+ UTRACE_ENTRY_OC(UTRACE_UCNV_UNLOAD);
+ UTRACE_DATA2(UTRACE_OPEN_CLOSE, "unload converter %s shared data %p", deadSharedData->staticData->name, deadSharedData);
+
+ if (deadSharedData->referenceCounter > 0) {
+ UTRACE_EXIT_VALUE((int32_t)FALSE);
+ return FALSE;
+ }
+
+ if (deadSharedData->impl->unload != NULL) {
+ deadSharedData->impl->unload(deadSharedData);
+ }
+
+ if(deadSharedData->dataMemory != NULL)
+ {
+ UDataMemory *data = (UDataMemory*)deadSharedData->dataMemory;
+ udata_close(data);
+ }
+
+ if(deadSharedData->table != NULL)
+ {
+ uprv_free(deadSharedData->table);
+ }
+
+#if 0
+ /* if the static data is actually owned by the shared data */
+ /* enable if we ever have this situation. */
+ if(deadSharedData->staticDataOwned == TRUE) /* see ucnv_bld.h */
+ {
+ uprv_free((void*)deadSharedData->staticData);
+ }
+#endif
+
+#if 0
+ /* Zap it ! */
+ uprv_memset(deadSharedData->0, sizeof(*deadSharedData));
+#endif
+
+ uprv_free(deadSharedData);
+
+ UTRACE_EXIT_VALUE((int32_t)TRUE);
+ return TRUE;
+}
+
+/**
+ * Load a non-algorithmic converter.
+ * If pkg==NULL, then this function must be called inside umtx_lock(&cnvCacheMutex).
+ */
+UConverterSharedData *
+ucnv_load(UConverterLoadArgs *pArgs, UErrorCode *err) {
+ UConverterSharedData *mySharedConverterData;
+
+ if(err == NULL || U_FAILURE(*err)) {
+ return NULL;
+ }
+
+ if(pArgs->pkg != NULL && *pArgs->pkg != 0) {
+ /* application-provided converters are not currently cached */
+ return createConverterFromFile(pArgs, err);
+ }
+
+ mySharedConverterData = ucnv_getSharedConverterData(pArgs->name);
+ if (mySharedConverterData == NULL)
+ {
+ /*Not cached, we need to stream it in from file */
+ mySharedConverterData = createConverterFromFile(pArgs, err);
+ if (U_FAILURE (*err) || (mySharedConverterData == NULL))
+ {
+ return NULL;
+ }
+ else
+ {
+ /* share it with other library clients */
+ ucnv_shareConverterData(mySharedConverterData);
+ }
+ }
+ else
+ {
+ /* The data for this converter was already in the cache. */
+ /* Update the reference counter on the shared data: one more client */
+ mySharedConverterData->referenceCounter++;
+ }
+
+ return mySharedConverterData;
+}
+
+/**
+ * Unload a non-algorithmic converter.
+ * It must be sharedData->referenceCounter != ~0
+ * and this function must be called inside umtx_lock(&cnvCacheMutex).
+ */
+void
+ucnv_unload(UConverterSharedData *sharedData) {
+ if(sharedData != NULL) {
+ if (sharedData->referenceCounter > 0) {
+ sharedData->referenceCounter--;
+ }
+
+ if((sharedData->referenceCounter <= 0)&&(sharedData->sharedDataCached == FALSE)) {
+ ucnv_deleteSharedConverterData(sharedData);
+ }
+ }
+}
+
+void
+ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData)
+{
+ /*
+ Checking whether it's an algorithic converter is okay
+ in multithreaded applications because the value never changes.
+ Don't check referenceCounter for any other value.
+ */
+ if(sharedData != NULL && sharedData->referenceCounter != ~0) {
+ umtx_lock(&cnvCacheMutex);
+ ucnv_unload(sharedData);
+ umtx_unlock(&cnvCacheMutex);
+ }
+}
+
+void
+ucnv_incrementRefCount(UConverterSharedData *sharedData)
+{
+ if(sharedData != NULL && sharedData->referenceCounter != ~0) {
+ umtx_lock(&cnvCacheMutex);
+ sharedData->referenceCounter++;
+ umtx_unlock(&cnvCacheMutex);
+ }
+}
+
+static void
+parseConverterOptions(const char *inName,
+ char *cnvName,
+ char *locale,
+ uint32_t *pFlags,
+ UErrorCode *err)
+{
+ char c;
+ int32_t len = 0;
+
+ /* copy the converter name itself to cnvName */
+ while((c=*inName)!=0 && c!=UCNV_OPTION_SEP_CHAR) {
+ if (++len>=UCNV_MAX_CONVERTER_NAME_LENGTH) {
+ *err = U_ILLEGAL_ARGUMENT_ERROR; /* bad name */
+ *cnvName=0;
+ return;
+ }
+ *cnvName++=c;
+ inName++;
+ }
+ *cnvName=0;
+
+ /* parse options. No more name copying should occur. */
+ while((c=*inName)!=0) {
+ if(c==UCNV_OPTION_SEP_CHAR) {
+ ++inName;
+ }
+
+ /* inName is behind an option separator */
+ if(uprv_strncmp(inName, "locale=", 7)==0) {
+ /* do not modify locale itself in case we have multiple locale options */
+ char *dest=locale;
+
+ /* copy the locale option value */
+ inName+=7;
+ len=0;
+ while((c=*inName)!=0 && c!=UCNV_OPTION_SEP_CHAR) {
+ ++inName;
+
+ if(++len>=ULOC_FULLNAME_CAPACITY) {
+ *err=U_ILLEGAL_ARGUMENT_ERROR; /* bad name */
+ *locale=0;
+ return;
+ }
+
+ *dest++=c;
+ }
+ *dest=0;
+ } else if(uprv_strncmp(inName, "version=", 8)==0) {
+ /* copy the version option value into bits 3..0 of *pFlags */
+ inName+=8;
+ c=*inName;
+ if(c==0) {
+ *pFlags&=~UCNV_OPTION_VERSION;
+ return;
+ } else if((uint8_t)(c-'0')<10) {
+ *pFlags=(*pFlags&~UCNV_OPTION_VERSION)|(uint32_t)(c-'0');
+ ++inName;
+ }
+ } else if(uprv_strncmp(inName, "swaplfnl", 8)==0) {
+ inName+=8;
+ *pFlags|=UCNV_OPTION_SWAP_LFNL;
+ /* add processing for new options here with another } else if(uprv_strncmp(inName, "option-name=", XX)==0) { */
+ } else {
+ /* ignore any other options until we define some */
+ while(((c = *inName++) != 0) && (c != UCNV_OPTION_SEP_CHAR)) {
+ }
+ if(c==0) {
+ return;
+ }
+ }
+ }
+}
+
+/*Logic determines if the converter is Algorithmic AND/OR cached
+ *depending on that:
+ * -we either go to get data from disk and cache it (Data=TRUE, Cached=False)
+ * -Get it from a Hashtable (Data=X, Cached=TRUE)
+ * -Call dataConverter initializer (Data=TRUE, Cached=TRUE)
+ * -Call AlgorithmicConverter initializer (Data=FALSE, Cached=TRUE)
+ */
+UConverterSharedData *
+ucnv_loadSharedData(const char *converterName, UConverterLookupData *lookup, UErrorCode * err) {
+ UConverterLookupData stackLookup;
+ UConverterSharedData *mySharedConverterData = NULL;
+ UErrorCode internalErrorCode = U_ZERO_ERROR;
+ UBool mayContainOption = TRUE;
+ UBool checkForAlgorithmic = TRUE;
+
+ if (U_FAILURE (*err)) {
+ return NULL;
+ }
+
+ if(lookup == NULL) {
+ lookup = &stackLookup;
+ }
+
+ lookup->locale[0] = 0;
+ lookup->options = 0;
+
+ /* In case "name" is NULL we want to open the default converter. */
+ if (converterName == NULL) {
+ /* Call ucnv_getDefaultName first to query the name from the OS. */
+ lookup->realName = ucnv_getDefaultName();
+ if (lookup->realName == NULL) {
+ *err = U_MISSING_RESOURCE_ERROR;
+ return NULL;
+ }
+ mySharedConverterData = (UConverterSharedData *)gDefaultAlgorithmicSharedData;
+ checkForAlgorithmic = FALSE;
+ mayContainOption = gDefaultConverterContainsOption;
+ /* the default converter name is already canonical */
+ }
+ else if((converterName[0] == 'U' ?
+ ( converterName[1] == 'T' && converterName[2] == 'F') :
+ (converterName[0] == 'u' && converterName[1] == 't' && converterName[2] == 'f'))
+ &&
+ (converterName[3] == '-' ?
+ (converterName[4] == '8' && converterName[5] == 0) :
+ (converterName[3] == '8' && converterName[4] == 0)))
+ {
+ /* fastpath for UTF-8 */
+ return (UConverterSharedData *)converterData[UCNV_UTF8];
+ }
+ else {
+ /* separate the converter name from the options */
+ parseConverterOptions(converterName, lookup->cnvName, lookup->locale, &lookup->options, err);
+ if (U_FAILURE(*err)) {
+ /* Very bad name used. */
+ return NULL;
+ }
+
+ /* get the canonical converter name */
+ lookup->realName = ucnv_io_getConverterName(lookup->cnvName, &mayContainOption, &internalErrorCode);
+ if (U_FAILURE(internalErrorCode) || lookup->realName == NULL) {
+ /*
+ * set the input name in case the converter was added
+ * without updating the alias table, or when there is no alias table
+ */
+ lookup->realName = lookup->cnvName;
+ }
+ }
+
+ /* separate the converter name from the options */
+ if(mayContainOption && lookup->realName != lookup->cnvName) {
+ parseConverterOptions(lookup->realName, lookup->cnvName, lookup->locale, &lookup->options, err);
+ lookup->realName = lookup->cnvName;
+ }
+
+ /* get the shared data for an algorithmic converter, if it is one */
+ if (checkForAlgorithmic) {
+ mySharedConverterData = (UConverterSharedData *)getAlgorithmicTypeFromName(lookup->realName);
+ }
+ if (mySharedConverterData == NULL)
+ {
+ /* it is a data-based converter, get its shared data. */
+ /* Hold the cnvCacheMutex through the whole process of checking the */
+ /* converter data cache, and adding new entries to the cache */
+ /* to prevent other threads from modifying the cache during the */
+ /* process. */
+ UConverterLoadArgs args={ 0 };
+
+ args.size=sizeof(UConverterLoadArgs);
+ args.nestedLoads=1;
+ args.options=lookup->options;
+ args.pkg=NULL;
+ args.name=lookup->realName;
+
+ umtx_lock(&cnvCacheMutex);
+ mySharedConverterData = ucnv_load(&args, err);
+ umtx_unlock(&cnvCacheMutex);
+ if (U_FAILURE (*err) || (mySharedConverterData == NULL))
+ {
+ return NULL;
+ }
+ }
+
+ return mySharedConverterData;
+}
+
+UConverter *
+ucnv_createConverter(UConverter *myUConverter, const char *converterName, UErrorCode * err)
+{
+ UConverterLookupData stackLookup;
+ UConverterSharedData *mySharedConverterData;
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN);
+
+ if(U_SUCCESS(*err)) {
+ UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open converter %s", converterName);
+
+ mySharedConverterData = ucnv_loadSharedData(converterName, &stackLookup, err);
+
+ if(U_SUCCESS(*err)) {
+ myUConverter = ucnv_createConverterFromSharedData(
+ myUConverter, mySharedConverterData,
+ stackLookup.realName, stackLookup.locale, stackLookup.options,
+ err);
+
+ if(U_SUCCESS(*err)) {
+ UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
+ return myUConverter;
+ } else {
+ ucnv_unloadSharedDataIfReady(mySharedConverterData);
+ }
+ }
+ }
+
+ /* exit with error */
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+}
+
+UConverter *
+ucnv_createAlgorithmicConverter(UConverter *myUConverter,
+ UConverterType type,
+ const char *locale, uint32_t options,
+ UErrorCode *err) {
+ UConverter *cnv;
+ const UConverterSharedData *sharedData;
+ UBool isAlgorithmicConverter;
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_ALGORITHMIC);
+ UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open algorithmic converter type %d", (int32_t)type);
+
+ if(type<0 || UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES<=type) {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
+ return NULL;
+ }
+
+ sharedData = converterData[type];
+ umtx_lock(&cnvCacheMutex);
+ isAlgorithmicConverter = (UBool)(sharedData == NULL || sharedData->referenceCounter != ~0);
+ umtx_unlock(&cnvCacheMutex);
+ if (isAlgorithmicConverter) {
+ /* not a valid type, or not an algorithmic converter */
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
+ return NULL;
+ }
+
+ cnv = ucnv_createConverterFromSharedData(myUConverter, (UConverterSharedData *)sharedData, "",
+ locale != NULL ? locale : "", options, err);
+
+ UTRACE_EXIT_PTR_STATUS(cnv, *err);
+ return cnv;
+}
+
+UConverter*
+ucnv_createConverterFromPackage(const char *packageName, const char *converterName, UErrorCode * err)
+{
+ char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH], locale[ULOC_FULLNAME_CAPACITY];
+ UConverter *myUConverter;
+ UConverterSharedData *mySharedConverterData;
+
+ UConverterLoadArgs args={ 0 };
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_PACKAGE);
+
+ if(U_FAILURE(*err)) {
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ UTRACE_DATA2(UTRACE_OPEN_CLOSE, "open converter %s from package %s", converterName, packageName);
+
+ args.size=sizeof(UConverterLoadArgs);
+ args.nestedLoads=1;
+ args.pkg=packageName;
+
+ /* first, get the options out of the converterName string */
+ parseConverterOptions(converterName, cnvName, locale, &args.options, err);
+ if (U_FAILURE(*err)) {
+ /* Very bad name used. */
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+ args.name=cnvName;
+
+ /* open the data, unflatten the shared structure */
+ mySharedConverterData = createConverterFromFile(&args, err);
+
+ if (U_FAILURE(*err)) {
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ /* create the actual converter */
+ myUConverter = ucnv_createConverterFromSharedData(NULL, mySharedConverterData, cnvName, locale, args.options, err);
+
+ if (U_FAILURE(*err)) {
+ ucnv_close(myUConverter);
+ UTRACE_EXIT_STATUS(*err);
+ return NULL;
+ }
+
+ UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
+ return myUConverter;
+}
+
+
+UConverter*
+ucnv_createConverterFromSharedData(UConverter *myUConverter,
+ UConverterSharedData *mySharedConverterData,
+ const char *realName, const char *locale, uint32_t options,
+ UErrorCode *err)
+{
+ UBool isCopyLocal;
+
+ if(myUConverter == NULL)
+ {
+ myUConverter = (UConverter *) uprv_malloc (sizeof (UConverter));
+ if(myUConverter == NULL)
+ {
+ *err = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ isCopyLocal = FALSE;
+ } else {
+ isCopyLocal = TRUE;
+ }
+
+ /* initialize the converter */
+ uprv_memset(myUConverter, 0, sizeof(UConverter));
+ myUConverter->isCopyLocal = isCopyLocal;
+ /*myUConverter->isExtraLocal = FALSE;*/ /* Set by the memset call */
+ myUConverter->sharedData = mySharedConverterData;
+ myUConverter->options = options;
+ myUConverter->preFromUFirstCP = U_SENTINEL;
+ myUConverter->fromCharErrorBehaviour = UCNV_TO_U_DEFAULT_CALLBACK;
+ myUConverter->fromUCharErrorBehaviour = UCNV_FROM_U_DEFAULT_CALLBACK;
+ myUConverter->toUnicodeStatus = mySharedConverterData->toUnicodeStatus;
+ myUConverter->maxBytesPerUChar = mySharedConverterData->staticData->maxBytesPerChar;
+ myUConverter->subChar1 = mySharedConverterData->staticData->subChar1;
+ myUConverter->subCharLen = mySharedConverterData->staticData->subCharLen;
+ myUConverter->subChars = (uint8_t *)myUConverter->subUChars;
+ uprv_memcpy(myUConverter->subChars, mySharedConverterData->staticData->subChar, myUConverter->subCharLen);
+
+ if(mySharedConverterData->impl->open != NULL) {
+ mySharedConverterData->impl->open(myUConverter, realName, locale, options, err);
+ if(U_FAILURE(*err)) {
+ ucnv_close(myUConverter);
+ return NULL;
+ }
+ }
+
+ return myUConverter;
+}
+
+static void
+ucnv_flushAvailableConverterCache() {
+ if (gAvailableConverters) {
+ umtx_lock(&cnvCacheMutex);
+ gAvailableConverterCount = 0;
+ uprv_free((char **)gAvailableConverters);
+ gAvailableConverters = NULL;
+ umtx_unlock(&cnvCacheMutex);
+ }
+}
+
+/*Frees all shared immutable objects that aren't referred to (reference count = 0)
+ */
+U_CAPI int32_t U_EXPORT2
+ucnv_flushCache ()
+{
+ UConverterSharedData *mySharedData = NULL;
+ int32_t pos;
+ int32_t tableDeletedNum = 0;
+ const UHashElement *e;
+ UErrorCode status = U_ILLEGAL_ARGUMENT_ERROR;
+ int32_t i, remaining;
+
+ UTRACE_ENTRY_OC(UTRACE_UCNV_FLUSH_CACHE);
+
+ /* Close the default converter without creating a new one so that everything will be flushed. */
+ ucnv_close(u_getDefaultConverter(&status));
+
+ /*if shared data hasn't even been lazy evaluated yet
+ * return 0
+ */
+ if (SHARED_DATA_HASHTABLE == NULL) {
+ UTRACE_EXIT_VALUE((int32_t)0);
+ return 0;
+ }
+
+ /*creates an enumeration to iterate through every element in the
+ * table
+ *
+ * Synchronization: holding cnvCacheMutex will prevent any other thread from
+ * accessing or modifying the hash table during the iteration.
+ * The reference count of an entry may be decremented by
+ * ucnv_close while the iteration is in process, but this is
+ * benign. It can't be incremented (in ucnv_createConverter())
+ * because the sequence of looking up in the cache + incrementing
+ * is protected by cnvCacheMutex.
+ */
+ umtx_lock(&cnvCacheMutex);
+ /*
+ * double loop: A delta/extension-only converter has a pointer to its base table's
+ * shared data; the first iteration of the outer loop may see the delta converter
+ * before the base converter, and unloading the delta converter may get the base
+ * converter's reference counter down to 0.
+ */
+ i = 0;
+ do {
+ remaining = 0;
+ pos = -1;
+ while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL)
+ {
+ mySharedData = (UConverterSharedData *) e->value.pointer;
+ /*deletes only if reference counter == 0 */
+ if (mySharedData->referenceCounter == 0)
+ {
+ tableDeletedNum++;
+
+ UCNV_DEBUG_LOG("del",mySharedData->staticData->name,mySharedData);
+
+ uhash_removeElement(SHARED_DATA_HASHTABLE, e);
+ mySharedData->sharedDataCached = FALSE;
+ ucnv_deleteSharedConverterData (mySharedData);
+ } else {
+ ++remaining;
+ }
+ }
+ } while(++i == 1 && remaining > 0);
+ umtx_unlock(&cnvCacheMutex);
+
+ UTRACE_DATA1(UTRACE_INFO, "ucnv_flushCache() exits with %d converters remaining", remaining);
+
+ ucnv_flushAvailableConverterCache();
+
+ UTRACE_EXIT_VALUE(tableDeletedNum);
+ return tableDeletedNum;
+}
+
+/* available converters list --------------------------------------------------- */
+
+static UBool haveAvailableConverterList(UErrorCode *pErrorCode) {
+ int needInit;
+ UMTX_CHECK(&cnvCacheMutex, (gAvailableConverters == NULL), needInit);
+ if (needInit) {
+ UConverter tempConverter;
+ UEnumeration *allConvEnum = NULL;
+ uint16_t idx;
+ uint16_t localConverterCount;
+ uint16_t allConverterCount;
+ UErrorCode localStatus;
+ const char *converterName;
+ const char **localConverterList;
+
+ allConvEnum = ucnv_openAllNames(pErrorCode);
+ allConverterCount = uenum_count(allConvEnum, pErrorCode);
+ if (U_FAILURE(*pErrorCode)) {
+ return FALSE;
+ }
+
+ /* We can't have more than "*converterTable" converters to open */
+ localConverterList = (const char **) uprv_malloc(allConverterCount * sizeof(char*));
+ if (!localConverterList) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+
+ /* Open the default converter to make sure that it has first dibs in the hash table. */
+ localStatus = U_ZERO_ERROR;
+ ucnv_close(ucnv_createConverter(&tempConverter, NULL, &localStatus));
+
+ localConverterCount = 0;
+
+ for (idx = 0; idx < allConverterCount; idx++) {
+ localStatus = U_ZERO_ERROR;
+ converterName = uenum_next(allConvEnum, NULL, &localStatus);
+ ucnv_close(ucnv_createConverter(&tempConverter, converterName, &localStatus));
+ if (U_SUCCESS(localStatus)) {
+ localConverterList[localConverterCount++] = converterName;
+ }
+ }
+ uenum_close(allConvEnum);
+
+ umtx_lock(&cnvCacheMutex);
+ if (gAvailableConverters == NULL) {
+ gAvailableConverters = localConverterList;
+ gAvailableConverterCount = localConverterCount;
+ ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
+ }
+ else {
+ uprv_free((char **)localConverterList);
+ }
+ umtx_unlock(&cnvCacheMutex);
+ }
+ return TRUE;
+}
+
+U_CFUNC uint16_t
+ucnv_bld_countAvailableConverters(UErrorCode *pErrorCode) {
+ if (haveAvailableConverterList(pErrorCode)) {
+ return gAvailableConverterCount;
+ }
+ return 0;
+}
+
+U_CFUNC const char *
+ucnv_bld_getAvailableConverter(uint16_t n, UErrorCode *pErrorCode) {
+ if (haveAvailableConverterList(pErrorCode)) {
+ if (n < gAvailableConverterCount) {
+ return gAvailableConverters[n];
+ }
+ *pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ return NULL;
+}
+
+/* default converter name --------------------------------------------------- */
+
+/*
+Copy the canonical converter name.
+ucnv_getDefaultName must be thread safe, which can call this function.
+
+ucnv_setDefaultName calls this function and it doesn't have to be
+thread safe because there is no reliable/safe way to reset the
+converter in use in all threads. If you did reset the converter, you
+would not be sure that retrieving a default converter for one string
+would be the same type of default converter for a successive string.
+Since the name is a returned via ucnv_getDefaultName without copying,
+you shouldn't be modifying or deleting the string from a separate thread.
+*/
+static U_INLINE void
+internalSetName(const char *name, UErrorCode *status) {
+ UConverterLookupData lookup;
+ int32_t length=(int32_t)(uprv_strlen(name));
+ UBool containsOption = (UBool)(uprv_strchr(name, UCNV_OPTION_SEP_CHAR) != NULL);
+ const UConverterSharedData *algorithmicSharedData;
+
+ lookup.locale[0] = 0;
+ lookup.options = 0;
+ lookup.realName = name;
+ if(containsOption) {
+ parseConverterOptions(lookup.realName, lookup.cnvName, lookup.locale, &lookup.options, status);
+ lookup.realName = lookup.cnvName;
+ }
+ algorithmicSharedData = getAlgorithmicTypeFromName(lookup.realName);
+
+ umtx_lock(&cnvCacheMutex);
+
+ gDefaultAlgorithmicSharedData = algorithmicSharedData;
+ gDefaultConverterContainsOption = containsOption;
+ uprv_memcpy(gDefaultConverterNameBuffer, name, length);
+ gDefaultConverterNameBuffer[length]=0;
+ gDefaultConverterName = gDefaultConverterNameBuffer;
+
+ ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup);
+
+ umtx_unlock(&cnvCacheMutex);
+}
+
+/*
+ * In order to be really thread-safe, the get function would have to take
+ * a buffer parameter and copy the current string inside a mutex block.
+ * This implementation only tries to be really thread-safe while
+ * setting the name.
+ * It assumes that setting a pointer is atomic.
+ */
+
+U_CAPI const char* U_EXPORT2
+ucnv_getDefaultName() {
+ /* local variable to be thread-safe */
+ const char *name;
+
+ /*
+ Multiple calls to ucnv_getDefaultName must be thread safe,
+ but ucnv_setDefaultName is not thread safe.
+ */
+ UMTX_CHECK(&cnvCacheMutex, gDefaultConverterName, name);
+ if(name==NULL) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ UConverter *cnv = NULL;
+
+ name = uprv_getDefaultCodepage();
+
+ /* if the name is there, test it out and get the canonical name with options */
+ if(name != NULL) {
+ cnv = ucnv_open(name, &errorCode);
+ if(U_SUCCESS(errorCode) && cnv != NULL) {
+ name = ucnv_getName(cnv, &errorCode);
+ }
+ }
+
+ if(name == NULL || name[0] == 0
+ || U_FAILURE(errorCode) || cnv == NULL
+ || uprv_strlen(name)>=sizeof(gDefaultConverterNameBuffer))
+ {
+ /* Panic time, let's use a fallback. */
+#if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
+ name = "US-ASCII";
+ /* there is no 'algorithmic' converter for EBCDIC */
+#elif defined(OS390)
+ name = "ibm-1047_P100-1995" UCNV_SWAP_LFNL_OPTION_STRING;
+#else
+ name = "ibm-37_P100-1995";
+#endif
+ }
+
+ internalSetName(name, &errorCode);
+
+ /* The close may make the current name go away. */
+ ucnv_close(cnv);
+ }
+
+ return name;
+}
+
+/*
+This function is not thread safe, and it can't be thread safe.
+See internalSetName or the API reference for details.
+*/
+U_CAPI void U_EXPORT2
+ucnv_setDefaultName(const char *converterName) {
+ if(converterName==NULL) {
+ /* reset to the default codepage */
+ gDefaultConverterName=NULL;
+ } else {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ UConverter *cnv = NULL;
+ const char *name = NULL;
+
+ /* if the name is there, test it out and get the canonical name with options */
+ cnv = ucnv_open(converterName, &errorCode);
+ if(U_SUCCESS(errorCode) && cnv != NULL) {
+ name = ucnv_getName(cnv, &errorCode);
+ }
+
+ if(U_SUCCESS(errorCode) && name!=NULL) {
+ internalSetName(name, &errorCode);
+ }
+ /* else this converter is bad to use. Don't change it to a bad value. */
+
+ /* The close may make the current name go away. */
+ ucnv_close(cnv);
+ }
+}
+
+/* data swapping ------------------------------------------------------------ */
+
+/* most of this might belong more properly into ucnvmbcs.c, but that is so large */
+
+#if !UCONFIG_NO_LEGACY_CONVERSION
+
+U_CAPI int32_t U_EXPORT2
+ucnv_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode) {
+ const UDataInfo *pInfo;
+ int32_t headerSize;
+
+ const uint8_t *inBytes;
+ uint8_t *outBytes;
+
+ uint32_t offset, count, staticDataSize;
+ int32_t size;
+
+ const UConverterStaticData *inStaticData;
+ UConverterStaticData *outStaticData;
+
+ const _MBCSHeader *inMBCSHeader;
+ _MBCSHeader *outMBCSHeader;
+ _MBCSHeader mbcsHeader;
+ uint8_t outputType;
+
+ int32_t maxFastUChar, mbcsIndexLength;
+
+ const int32_t *inExtIndexes;
+ int32_t extOffset;
+
+ /* udata_swapDataHeader checks the arguments */
+ headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* check data format and format version */
+ pInfo=(const UDataInfo *)((const char *)inData+4);
+ if(!(
+ pInfo->dataFormat[0]==0x63 && /* dataFormat="cnvt" */
+ pInfo->dataFormat[1]==0x6e &&
+ pInfo->dataFormat[2]==0x76 &&
+ pInfo->dataFormat[3]==0x74 &&
+ pInfo->formatVersion[0]==6 &&
+ pInfo->formatVersion[1]>=2
+ )) {
+ udata_printError(ds, "ucnv_swap(): data format %02x.%02x.%02x.%02x (format version %02x.%02x) is not recognized as an ICU .cnv conversion table\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0], pInfo->formatVersion[1]);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ inBytes=(const uint8_t *)inData+headerSize;
+ outBytes=(uint8_t *)outData+headerSize;
+
+ /* read the initial UConverterStaticData structure after the UDataInfo header */
+ inStaticData=(const UConverterStaticData *)inBytes;
+ outStaticData=(UConverterStaticData *)outBytes;
+
+ if(length<0) {
+ staticDataSize=ds->readUInt32(inStaticData->structSize);
+ } else {
+ length-=headerSize;
+ if( lengthreadUInt32(inStaticData->structSize))
+ ) {
+ udata_printError(ds, "ucnv_swap(): too few bytes (%d after header) for an ICU .cnv conversion table\n",
+ length);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ }
+
+ if(length>=0) {
+ /* swap the static data */
+ if(inStaticData!=outStaticData) {
+ uprv_memcpy(outStaticData, inStaticData, staticDataSize);
+ }
+
+ ds->swapArray32(ds, &inStaticData->structSize, 4,
+ &outStaticData->structSize, pErrorCode);
+ ds->swapArray32(ds, &inStaticData->codepage, 4,
+ &outStaticData->codepage, pErrorCode);
+
+ ds->swapInvChars(ds, inStaticData->name, (int32_t)uprv_strlen(inStaticData->name),
+ outStaticData->name, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ udata_printError(ds, "ucnv_swap(): error swapping converter name\n");
+ return 0;
+ }
+ }
+
+ inBytes+=staticDataSize;
+ outBytes+=staticDataSize;
+ if(length>=0) {
+ length-=(int32_t)staticDataSize;
+ }
+
+ /* check for supported conversionType values */
+ if(inStaticData->conversionType==UCNV_MBCS) {
+ /* swap MBCS data */
+ inMBCSHeader=(const _MBCSHeader *)inBytes;
+ outMBCSHeader=(_MBCSHeader *)outBytes;
+
+ if(0<=length && lengthversion[0]==4 && inMBCSHeader->version[1]>=1)) {
+ udata_printError(ds, "ucnv_swap(): unsupported _MBCSHeader.version %d.%d\n",
+ inMBCSHeader->version[0], inMBCSHeader->version[1]);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ uprv_memcpy(mbcsHeader.version, inMBCSHeader->version, 4);
+ mbcsHeader.countStates= ds->readUInt32(inMBCSHeader->countStates);
+ mbcsHeader.countToUFallbacks= ds->readUInt32(inMBCSHeader->countToUFallbacks);
+ mbcsHeader.offsetToUCodeUnits= ds->readUInt32(inMBCSHeader->offsetToUCodeUnits);
+ mbcsHeader.offsetFromUTable= ds->readUInt32(inMBCSHeader->offsetFromUTable);
+ mbcsHeader.offsetFromUBytes= ds->readUInt32(inMBCSHeader->offsetFromUBytes);
+ mbcsHeader.flags= ds->readUInt32(inMBCSHeader->flags);
+ mbcsHeader.fromUBytesLength= ds->readUInt32(inMBCSHeader->fromUBytesLength);
+
+ extOffset=(int32_t)(mbcsHeader.flags>>8);
+ outputType=(uint8_t)mbcsHeader.flags;
+
+ /* make sure that the output type is known */
+ switch(outputType) {
+ case MBCS_OUTPUT_1:
+ case MBCS_OUTPUT_2:
+ case MBCS_OUTPUT_3:
+ case MBCS_OUTPUT_4:
+ case MBCS_OUTPUT_3_EUC:
+ case MBCS_OUTPUT_4_EUC:
+ case MBCS_OUTPUT_2_SISO:
+ case MBCS_OUTPUT_EXT_ONLY:
+ /* OK */
+ break;
+ default:
+ udata_printError(ds, "ucnv_swap(): unsupported MBCS output type 0x%x\n",
+ outputType);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ /* calculate the length of the MBCS data */
+
+ /*
+ * utf8Friendly MBCS files (mbcsHeader.version 4.3)
+ * contain an additional mbcsIndex table:
+ * uint16_t[(maxFastUChar+1)>>6];
+ * where maxFastUChar=((mbcsHeader.version[2]<<8)|0xff).
+ */
+ maxFastUChar=0;
+ mbcsIndexLength=0;
+ if( outputType!=MBCS_OUTPUT_EXT_ONLY && outputType!=MBCS_OUTPUT_1 &&
+ mbcsHeader.version[1]>=3 && (maxFastUChar=mbcsHeader.version[2])!=0
+ ) {
+ maxFastUChar=(maxFastUChar<<8)|0xff;
+ mbcsIndexLength=((maxFastUChar+1)>>6)*2; /* number of bytes */
+ }
+
+ if(extOffset==0) {
+ size=(int32_t)(mbcsHeader.offsetFromUBytes+mbcsHeader.fromUBytesLength+mbcsIndexLength);
+
+ /* avoid compiler warnings - not otherwise necessary, and the value does not matter */
+ inExtIndexes=NULL;
+ } else {
+ /* there is extension data after the base data, see ucnv_ext.h */
+ if(length>=0 && length<(extOffset+UCNV_EXT_INDEXES_MIN_LENGTH*4)) {
+ udata_printError(ds, "ucnv_swap(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table with extension data\n",
+ length);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+ inExtIndexes=(const int32_t *)(inBytes+extOffset);
+ size=extOffset+udata_readInt32(ds, inExtIndexes[UCNV_EXT_SIZE]);
+ }
+
+ if(length>=0) {
+ if(lengthswapArray32(ds, &inMBCSHeader->countStates, 7*4,
+ &outMBCSHeader->countStates, pErrorCode);
+
+ if(outputType==MBCS_OUTPUT_EXT_ONLY) {
+ /*
+ * extension-only file,
+ * contains a base name instead of normal base table data
+ */
+
+ /* swap the base name, between the header and the extension data */
+ ds->swapInvChars(ds, inMBCSHeader+1, (int32_t)uprv_strlen((const char *)(inMBCSHeader+1)),
+ outMBCSHeader+1, pErrorCode);
+ } else {
+ /* normal file with base table data */
+
+ /* swap the state table, 1kB per state */
+ ds->swapArray32(ds, inMBCSHeader+1, (int32_t)(mbcsHeader.countStates*1024),
+ outMBCSHeader+1, pErrorCode);
+
+ /* swap the toUFallbacks[] */
+ offset=sizeof(_MBCSHeader)+mbcsHeader.countStates*1024;
+ ds->swapArray32(ds, inBytes+offset, (int32_t)(mbcsHeader.countToUFallbacks*8),
+ outBytes+offset, pErrorCode);
+
+ /* swap the unicodeCodeUnits[] */
+ offset=mbcsHeader.offsetToUCodeUnits;
+ count=mbcsHeader.offsetFromUTable-offset;
+ ds->swapArray16(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+
+ /* offset to the stage 1 table, independent of the outputType */
+ offset=mbcsHeader.offsetFromUTable;
+
+ if(outputType==MBCS_OUTPUT_1) {
+ /* SBCS: swap the fromU tables, all 16 bits wide */
+ count=(mbcsHeader.offsetFromUBytes-offset)+mbcsHeader.fromUBytesLength;
+ ds->swapArray16(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+ } else {
+ /* otherwise: swap the stage tables separately */
+
+ /* stage 1 table: uint16_t[0x440 or 0x40] */
+ if(inStaticData->unicodeMask&UCNV_HAS_SUPPLEMENTARY) {
+ count=0x440*2; /* for all of Unicode */
+ } else {
+ count=0x40*2; /* only BMP */
+ }
+ ds->swapArray16(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+
+ /* stage 2 table: uint32_t[] */
+ offset+=count;
+ count=mbcsHeader.offsetFromUBytes-offset;
+ ds->swapArray32(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+
+ /* stage 3/result bytes: sometimes uint16_t[] or uint32_t[] */
+ offset=mbcsHeader.offsetFromUBytes;
+ count=mbcsHeader.fromUBytesLength;
+ switch(outputType) {
+ case MBCS_OUTPUT_2:
+ case MBCS_OUTPUT_3_EUC:
+ case MBCS_OUTPUT_2_SISO:
+ ds->swapArray16(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+ break;
+ case MBCS_OUTPUT_4:
+ ds->swapArray32(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+ break;
+ default:
+ /* just uint8_t[], nothing to swap */
+ break;
+ }
+
+ if(mbcsIndexLength!=0) {
+ offset+=count;
+ count=mbcsIndexLength;
+ ds->swapArray16(ds, inBytes+offset, (int32_t)count,
+ outBytes+offset, pErrorCode);
+ }
+ }
+ }
+
+ if(extOffset!=0) {
+ /* swap the extension data */
+ inBytes+=extOffset;
+ outBytes+=extOffset;
+
+ /* swap toUTable[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_LENGTH]);
+ ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
+
+ /* swap toUUChars[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_UCHARS_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_TO_U_UCHARS_LENGTH]);
+ ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
+
+ /* swap fromUTableUChars[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_UCHARS_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_LENGTH]);
+ ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
+
+ /* swap fromUTableValues[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_VALUES_INDEX]);
+ /* same length as for fromUTableUChars[] */
+ ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
+
+ /* no need to swap fromUBytes[] */
+
+ /* swap fromUStage12[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_12_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_12_LENGTH]);
+ ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
+
+ /* swap fromUStage3[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3_LENGTH]);
+ ds->swapArray16(ds, inBytes+offset, length*2, outBytes+offset, pErrorCode);
+
+ /* swap fromUStage3b[] */
+ offset=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3B_INDEX]);
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_FROM_U_STAGE_3B_LENGTH]);
+ ds->swapArray32(ds, inBytes+offset, length*4, outBytes+offset, pErrorCode);
+
+ /* swap indexes[] */
+ length=udata_readInt32(ds, inExtIndexes[UCNV_EXT_INDEXES_LENGTH]);
+ ds->swapArray32(ds, inBytes, length*4, outBytes, pErrorCode);
+ }
+ }
+ } else {
+ udata_printError(ds, "ucnv_swap(): unknown conversionType=%d!=UCNV_MBCS\n",
+ inStaticData->conversionType);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ return headerSize+(int32_t)staticDataSize+size;
+}
+
+#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_bld.h b/Build/source/libs/icu/icu-xetex/common/ucnv_bld.h
new file mode 100644
index 00000000000..75aa4d183ab
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_bld.h
@@ -0,0 +1,281 @@
+/*
+**********************************************************************
+* Copyright (C) 1999-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+*
+* ucnv_bld.h:
+* Contains internal data structure definitions
+* Created by Bertrand A. Damiba
+*
+* Change history:
+*
+* 06/29/2000 helena Major rewrite of the callback APIs.
+*/
+
+#ifndef UCNV_BLD_H
+#define UCNV_BLD_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "unicode/ucnv_err.h"
+#include "ucnv_cnv.h"
+#include "ucnvmbcs.h"
+#include "ucnv_ext.h"
+#include "udataswp.h"
+
+/* size of the overflow buffers in UConverter, enough for escaping callbacks */
+#define UCNV_ERROR_BUFFER_LENGTH 32
+
+/* at most 4 bytes per substitution character (part of .cnv file format! see UConverterStaticData) */
+#define UCNV_MAX_SUBCHAR_LEN 4
+
+/* at most 8 bytes per character in toUBytes[] (UTF-8 uses up to 6) */
+#define UCNV_MAX_CHAR_LEN 8
+
+/* converter options bits */
+#define UCNV_OPTION_VERSION 0xf
+#define UCNV_OPTION_SWAP_LFNL 0x10
+
+
+U_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv
+ itself is compiled under C++, the linkage of the funcptrs will
+ work.
+ */
+
+union UConverterTable {
+ UConverterMBCSTable mbcs;
+};
+
+typedef union UConverterTable UConverterTable;
+
+struct UConverterImpl;
+typedef struct UConverterImpl UConverterImpl;
+
+/** values for the unicodeMask */
+#define UCNV_HAS_SUPPLEMENTARY 1
+#define UCNV_HAS_SURROGATES 2
+
+typedef struct UConverterStaticData { /* +offset: size */
+ uint32_t structSize; /* +0: 4 Size of this structure */
+
+ char name
+ [UCNV_MAX_CONVERTER_NAME_LENGTH]; /* +4: 60 internal name of the converter- invariant chars */
+
+ int32_t codepage; /* +64: 4 codepage # (now IBM-$codepage) */
+
+ int8_t platform; /* +68: 1 platform of the converter (only IBM now) */
+ int8_t conversionType; /* +69: 1 conversion type */
+
+ int8_t minBytesPerChar; /* +70: 1 Minimum # bytes per char in this codepage */
+ int8_t maxBytesPerChar; /* +71: 1 Maximum # bytes output per UChar in this codepage */
+
+ uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* +72: 4 [note: 4 and 8 byte boundary] */
+ int8_t subCharLen; /* +76: 1 */
+
+ uint8_t hasToUnicodeFallback; /* +77: 1 UBool needs to be changed to UBool to be consistent across platform */
+ uint8_t hasFromUnicodeFallback; /* +78: 1 */
+ uint8_t unicodeMask; /* +79: 1 bit 0: has supplementary bit 1: has single surrogates */
+ uint8_t subChar1; /* +80: 1 single-byte substitution character for IBM MBCS (0 if none) */
+ uint8_t reserved[19]; /* +81: 19 to round out the structure */
+ /* total size: 100 */
+} UConverterStaticData;
+
+/*
+ * Defines the UConverterSharedData struct,
+ * the immutable, shared part of UConverter.
+ */
+struct UConverterSharedData {
+ uint32_t structSize; /* Size of this structure */
+ uint32_t referenceCounter; /* used to count number of clients, 0xffffffff for static SharedData */
+
+ const void *dataMemory; /* from udata_openChoice() - for cleanup */
+ void *table; /* Unused. This used to be a UConverterTable - Pointer to conversion data - see mbcs below */
+
+ const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */
+
+ UBool sharedDataCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */
+ /*UBool staticDataOwned; TRUE if static data owned by shared data & should be freed with it, NEVER true for udata() loaded statics. This ignored variable was removed to make space for sharedDataCached. */
+
+ const UConverterImpl *impl; /* vtable-style struct of mostly function pointers */
+
+ /*initial values of some members of the mutable part of object */
+ uint32_t toUnicodeStatus;
+
+ /*
+ * Shared data structures currently come in two flavors:
+ * - readonly for built-in algorithmic converters
+ * - allocated for MBCS, with a pointer to an allocated UConverterTable
+ * which always has a UConverterMBCSTable
+ *
+ * To eliminate one allocation, I am making the UConverterMBCSTable
+ * a member of the shared data. It is the last member so that static
+ * definitions of UConverterSharedData work as before.
+ * The table field above also remains to avoid updating all static
+ * definitions, but is now unused.
+ *
+ * markus 2003-nov-07
+ */
+ UConverterMBCSTable mbcs;
+};
+
+/* Defines a UConverter, the lightweight mutable part the user sees */
+
+struct UConverter {
+ /*
+ * Error function pointer called when conversion issues
+ * occur during a ucnv_fromUnicode call
+ */
+ void (U_EXPORT2 *fromUCharErrorBehaviour) (const void *context,
+ UConverterFromUnicodeArgs *args,
+ const UChar *codeUnits,
+ int32_t length,
+ UChar32 codePoint,
+ UConverterCallbackReason reason,
+ UErrorCode *);
+ /*
+ * Error function pointer called when conversion issues
+ * occur during a ucnv_toUnicode call
+ */
+ void (U_EXPORT2 *fromCharErrorBehaviour) (const void *context,
+ UConverterToUnicodeArgs *args,
+ const char *codeUnits,
+ int32_t length,
+ UConverterCallbackReason reason,
+ UErrorCode *);
+
+ /*
+ * Pointer to additional data that depends on the converter type.
+ * Used by ISO 2022, SCSU, GB 18030 converters, possibly more.
+ */
+ void *extraInfo;
+
+ const void *fromUContext;
+ const void *toUContext;
+
+ /*
+ * Pointer to charset bytes for substitution string if subCharLen>0,
+ * or pointer to Unicode string (UChar *) if subCharLen<0.
+ * subCharLen==0 is equivalent to using a skip callback.
+ * If the pointer is !=subUChars then it is allocated with
+ * UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR bytes.
+ * The subUChars field is declared as UChar[] not uint8_t[] to
+ * guarantee alignment for UChars.
+ */
+ uint8_t *subChars;
+
+ UConverterSharedData *sharedData; /* Pointer to the shared immutable part of the converter object */
+
+ uint32_t options; /* options flags from UConverterOpen, may contain additional bits */
+
+ UBool sharedDataIsCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */
+ UBool isCopyLocal; /* TRUE if UConverter is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */
+ UBool isExtraLocal; /* TRUE if extraInfo is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */
+
+ UBool useFallback;
+ int8_t toULength; /* number of bytes in toUBytes */
+ uint8_t toUBytes[UCNV_MAX_CHAR_LEN-1];/* more "toU status"; keeps the bytes of the current character */
+ uint32_t toUnicodeStatus; /* Used to internalize stream status information */
+ int32_t mode;
+ uint32_t fromUnicodeStatus;
+
+ /*
+ * More fromUnicode() status. Serves 3 purposes:
+ * - keeps a lead surrogate between buffers (similar to toUBytes[])
+ * - keeps a lead surrogate at the end of the stream,
+ * which the framework handles as truncated input
+ * - if the fromUnicode() implementation returns to the framework
+ * (ucnv.c ucnv_fromUnicode()), then the framework calls the callback
+ * for this code point
+ */
+ UChar32 fromUChar32;
+
+ /*
+ * value for ucnv_getMaxCharSize()
+ *
+ * usually simply copied from the static data, but ucnvmbcs.c modifies
+ * the value depending on the converter type and options
+ */
+ int8_t maxBytesPerUChar;
+
+ int8_t subCharLen; /* length of the codepage specific character sequence */
+ int8_t invalidCharLength;
+ int8_t charErrorBufferLength; /* number of valid bytes in charErrorBuffer */
+
+ int8_t invalidUCharLength;
+ int8_t UCharErrorBufferLength; /* number of valid UChars in charErrorBuffer */
+
+ uint8_t subChar1; /* single-byte substitution character if different from subChar */
+ UBool useSubChar1;
+ char invalidCharBuffer[UCNV_MAX_CHAR_LEN]; /* bytes from last error/callback situation */
+ uint8_t charErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* codepage output from Error functions */
+ UChar subUChars[UCNV_MAX_SUBCHAR_LEN/U_SIZEOF_UCHAR]; /* see subChars documentation */
+
+ UChar invalidUCharBuffer[U16_MAX_LENGTH]; /* UChars from last error/callback situation */
+ UChar UCharErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* unicode output from Error functions */
+
+ /* fields for conversion extension */
+
+ /* store previous UChars/chars to continue partial matches */
+ UChar32 preFromUFirstCP; /* >=0: partial match */
+ UChar preFromU[UCNV_EXT_MAX_UCHARS];
+ char preToU[UCNV_EXT_MAX_BYTES];
+ int8_t preFromULength, preToULength; /* negative: replay */
+ int8_t preToUFirstLength; /* length of first character */
+};
+
+U_CDECL_END /* end of UConverter */
+
+#define CONVERTER_FILE_EXTENSION ".cnv"
+
+
+/**
+ * Return the number of all converter names.
+ * @param pErrorCode The error code
+ * @return the number of all converter names
+ */
+U_CFUNC uint16_t
+ucnv_bld_countAvailableConverters(UErrorCode *pErrorCode);
+
+/**
+ * Return the (n)th converter name in mixed case, or NULL
+ * if there is none (typically, if the data cannot be loaded).
+ * 0<=indexreferenceCounter != ~0
+ * and this function must be called inside umtx_lock(&cnvCacheMutex).
+ */
+void
+ucnv_unload(UConverterSharedData *sharedData);
+
+/**
+ * Swap ICU .cnv conversion tables. See udataswp.h.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+ucnv_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+#endif
+
+#endif /* _UCNV_BLD */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_cb.c b/Build/source/libs/icu/icu-xetex/common/ucnv_cb.c
new file mode 100644
index 00000000000..fa34b658327
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_cb.c
@@ -0,0 +1,259 @@
+/*
+**********************************************************************
+* Copyright (C) 2000-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+ * ucnv_cb.c:
+ * External APIs for the ICU's codeset conversion library
+ * Helena Shih
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 7/28/2000 srl Implementation
+ */
+
+/**
+ * @name Character Conversion C API
+ *
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv_cb.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+#include "cmemory.h"
+
+/* need to update the offsets when the target moves. */
+/* Note: Recursion may occur in the cb functions, be sure to update the offsets correctly
+if you don't use ucnv_cbXXX functions. Make sure you don't use the same callback within
+the same call stack if the complexity arises. */
+U_CAPI void U_EXPORT2
+ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args,
+ const char* source,
+ int32_t length,
+ int32_t offsetIndex,
+ UErrorCode * err)
+{
+ if(U_FAILURE(*err)) {
+ return;
+ }
+
+ ucnv_fromUWriteBytes(
+ args->converter,
+ source, length,
+ &args->target, args->targetLimit,
+ &args->offsets, offsetIndex,
+ err);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args,
+ const UChar** source,
+ const UChar* sourceLimit,
+ int32_t offsetIndex,
+ UErrorCode * err)
+{
+ /*
+ This is a fun one. Recursion can occur - we're basically going to
+ just retry shoving data through the same converter. Note, if you got
+ here through some kind of invalid sequence, you maybe should emit a
+ reset sequence of some kind and/or call ucnv_reset(). Since this
+ IS an actual conversion, take care that you've changed the callback
+ or the data, or you'll get an infinite loop.
+
+ Please set the err value to something reasonable before calling
+ into this.
+ */
+
+ char *oldTarget;
+
+ if(U_FAILURE(*err))
+ {
+ return;
+ }
+
+ oldTarget = args->target;
+
+ ucnv_fromUnicode(args->converter,
+ &args->target,
+ args->targetLimit,
+ source,
+ sourceLimit,
+ NULL, /* no offsets */
+ FALSE, /* no flush */
+ err);
+
+ if(args->offsets)
+ {
+ while (args->target != oldTarget) /* if it moved at all.. */
+ {
+ *(args->offsets)++ = offsetIndex;
+ oldTarget++;
+ }
+ }
+
+ /*
+ Note, if you did something like used a Stop subcallback, things would get interesting.
+ In fact, here's where we want to return the partially consumed in-source!
+ */
+ if(*err == U_BUFFER_OVERFLOW_ERROR)
+ /* && (*source < sourceLimit && args->target >= args->targetLimit)
+ -- S. Hrcek */
+ {
+ /* Overflowed the target. Now, we'll write into the charErrorBuffer.
+ It's a fixed size. If we overflow it... Hmm */
+ char *newTarget;
+ const char *newTargetLimit;
+ UErrorCode err2 = U_ZERO_ERROR;
+
+ int8_t errBuffLen;
+
+ errBuffLen = args->converter->charErrorBufferLength;
+
+ /* start the new target at the first free slot in the errbuff.. */
+ newTarget = (char *)(args->converter->charErrorBuffer + errBuffLen);
+
+ newTargetLimit = (char *)(args->converter->charErrorBuffer +
+ sizeof(args->converter->charErrorBuffer));
+
+ if(newTarget >= newTargetLimit)
+ {
+ *err = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+
+ /* We're going to tell the converter that the errbuff len is empty.
+ This prevents the existing errbuff from being 'flushed' out onto
+ itself. If the errbuff is needed by the converter this time,
+ we're hosed - we're out of space! */
+
+ args->converter->charErrorBufferLength = 0;
+
+ ucnv_fromUnicode(args->converter,
+ &newTarget,
+ newTargetLimit,
+ source,
+ sourceLimit,
+ NULL,
+ FALSE,
+ &err2);
+
+ /* We can go ahead and overwrite the length here. We know just how
+ to recalculate it. */
+
+ args->converter->charErrorBufferLength = (int8_t)(
+ newTarget - (char*)args->converter->charErrorBuffer);
+
+ if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR))
+ {
+ /* now we're REALLY in trouble.
+ Internal program error - callback shouldn't have written this much
+ data!
+ */
+ *err = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ /*else {*/
+ /* sub errs could be invalid/truncated/illegal chars or w/e.
+ These might want to be passed on up.. But the problem is, we already
+ need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these
+ other errs.. */
+
+ /*
+ if(U_FAILURE(err2))
+ ??
+ */
+ /*}*/
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args,
+ int32_t offsetIndex,
+ UErrorCode * err)
+{
+ UConverter *converter;
+ int32_t length;
+
+ if(U_FAILURE(*err)) {
+ return;
+ }
+ converter = args->converter;
+ length = converter->subCharLen;
+
+ if(length == 0) {
+ return;
+ }
+
+ if(length < 0) {
+ /*
+ * Write/convert the substitution string. Its real length is -length.
+ * Unlike the escape callback, we need not change the converter's
+ * callback function because ucnv_setSubstString() verified that
+ * the string can be converted, so we will not get a conversion error
+ * and will not recurse.
+ * At worst we should get a U_BUFFER_OVERFLOW_ERROR.
+ */
+ const UChar *source = (const UChar *)converter->subChars;
+ ucnv_cbFromUWriteUChars(args, &source, source - length, offsetIndex, err);
+ return;
+ }
+
+ if(converter->sharedData->impl->writeSub!=NULL) {
+ converter->sharedData->impl->writeSub(args, offsetIndex, err);
+ }
+ else if(converter->subChar1!=0 && (uint16_t)converter->invalidUCharBuffer[0]<=(uint16_t)0xffu) {
+ /*
+ TODO: Is this untestable because the MBCS converter has a writeSub function to call
+ and the other converters don't use subChar1?
+ */
+ ucnv_cbFromUWriteBytes(args,
+ (const char *)&converter->subChar1, 1,
+ offsetIndex, err);
+ }
+ else {
+ ucnv_cbFromUWriteBytes(args,
+ (const char *)converter->subChars, length,
+ offsetIndex, err);
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args,
+ const UChar* source,
+ int32_t length,
+ int32_t offsetIndex,
+ UErrorCode * err)
+{
+ if(U_FAILURE(*err)) {
+ return;
+ }
+
+ ucnv_toUWriteUChars(
+ args->converter,
+ source, length,
+ &args->target, args->targetLimit,
+ &args->offsets, offsetIndex,
+ err);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args,
+ int32_t offsetIndex,
+ UErrorCode * err)
+{
+ static const UChar kSubstituteChar1 = 0x1A, kSubstituteChar = 0xFFFD;
+
+ /* could optimize this case, just one uchar */
+ if(args->converter->invalidCharLength == 1 && args->converter->subChar1 != 0) {
+ ucnv_cbToUWriteUChars(args, &kSubstituteChar1, 1, offsetIndex, err);
+ } else {
+ ucnv_cbToUWriteUChars(args, &kSubstituteChar, 1, offsetIndex, err);
+ }
+}
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.c b/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.c
new file mode 100644
index 00000000000..f8e2f830f91
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.c
@@ -0,0 +1,174 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+* uconv_cnv.c:
+* Implements all the low level conversion functions
+* T_UnicodeConverter_{to,from}Unicode_$ConversionType
+*
+* Change history:
+*
+* 06/29/2000 helena Major rewrite of the callback APIs.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv_err.h"
+#include "unicode/ucnv.h"
+#include "unicode/uset.h"
+#include "ucnv_cnv.h"
+#include "ucnv_bld.h"
+#include "cmemory.h"
+
+U_CFUNC void
+ucnv_getCompleteUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode) {
+ sa->addRange(sa->set, 0, 0x10ffff);
+}
+
+U_CFUNC void
+ucnv_getNonSurrogateUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode) {
+ sa->addRange(sa->set, 0, 0xd7ff);
+ sa->addRange(sa->set, 0xe000, 0x10ffff);
+}
+
+U_CFUNC void
+ucnv_fromUWriteBytes(UConverter *cnv,
+ const char *bytes, int32_t length,
+ char **target, const char *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode) {
+ char *t=*target;
+ int32_t *o;
+
+ /* write bytes */
+ if(offsets==NULL || (o=*offsets)==NULL) {
+ while(length>0 && t0 && t0) {
+ if(cnv!=NULL) {
+ t=(char *)cnv->charErrorBuffer;
+ cnv->charErrorBufferLength=(int8_t)length;
+ do {
+ *t++=(uint8_t)*bytes++;
+ } while(--length>0);
+ }
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+}
+
+U_CFUNC void
+ucnv_toUWriteUChars(UConverter *cnv,
+ const UChar *uchars, int32_t length,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode) {
+ UChar *t=*target;
+ int32_t *o;
+
+ /* write UChars */
+ if(offsets==NULL || (o=*offsets)==NULL) {
+ while(length>0 && t0 && t0) {
+ if(cnv!=NULL) {
+ t=cnv->UCharErrorBuffer;
+ cnv->UCharErrorBufferLength=(int8_t)length;
+ do {
+ *t++=*uchars++;
+ } while(--length>0);
+ }
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+}
+
+U_CFUNC void
+ucnv_toUWriteCodePoint(UConverter *cnv,
+ UChar32 c,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode) {
+ UChar *t;
+ int32_t *o;
+
+ t=*target;
+
+ if(t=0) {
+ if(cnv!=NULL) {
+ int8_t i=0;
+ U16_APPEND_UNSAFE(cnv->UCharErrorBuffer, i, c);
+ cnv->UCharErrorBufferLength=i;
+ }
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+}
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.h b/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.h
new file mode 100644
index 00000000000..cf612a754da
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_cnv.h
@@ -0,0 +1,303 @@
+/*
+**********************************************************************
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+* ucnv_cnv.h:
+* Definitions for converter implementations.
+*
+* Modification History:
+*
+* Date Name Description
+* 05/09/00 helena Added implementation to handle fallback mappings.
+* 06/29/2000 helena Major rewrite of the callback APIs.
+*/
+
+#ifndef UCNV_CNV_H
+#define UCNV_CNV_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "unicode/ucnv_err.h"
+#include "unicode/uset.h"
+#include "uset_imp.h"
+
+U_CDECL_BEGIN
+
+/* this is used in fromUnicode DBCS tables as an "unassigned" marker */
+#define missingCharMarker 0xFFFF
+
+/*
+ * #define missingUCharMarker 0xfffe
+ *
+ * commented out because there are actually two values used in toUnicode tables:
+ * U+fffe "unassigned"
+ * U+ffff "illegal"
+ */
+
+/** Forward declaration, see ucnv_bld.h */
+struct UConverterSharedData;
+typedef struct UConverterSharedData UConverterSharedData;
+
+/* function types for UConverterImpl ---------------------------------------- */
+
+/* struct with arguments for UConverterLoad and ucnv_load() */
+typedef struct {
+ int32_t size; /* sizeof(UConverterLoadArgs) */
+ int32_t nestedLoads; /* count nested ucnv_load() calls */
+ int32_t reserved; /* reserved - for good alignment of the pointers */
+ uint32_t options;
+ const char *pkg, *name;
+} UConverterLoadArgs;
+
+typedef void (*UConverterLoad) (UConverterSharedData *sharedData,
+ UConverterLoadArgs *pArgs,
+ const uint8_t *raw, UErrorCode *pErrorCode);
+typedef void (*UConverterUnload) (UConverterSharedData *sharedData);
+
+typedef void (*UConverterOpen) (UConverter *cnv, const char *name, const char *locale,uint32_t options, UErrorCode *pErrorCode);
+typedef void (*UConverterClose) (UConverter *cnv);
+
+typedef enum UConverterResetChoice {
+ UCNV_RESET_BOTH,
+ UCNV_RESET_TO_UNICODE,
+ UCNV_RESET_FROM_UNICODE
+} UConverterResetChoice;
+
+typedef void (*UConverterReset) (UConverter *cnv, UConverterResetChoice choice);
+
+/*
+ * Converter implementation function(s) for ucnv_toUnicode().
+ * If the toUnicodeWithOffsets function pointer is NULL,
+ * then the toUnicode function will be used and the offsets will be set to -1.
+ *
+ * Must maintain state across buffers. Use toUBytes[toULength] for partial input
+ * sequences; it will be checked in ucnv.c at the end of the input stream
+ * to detect truncated input.
+ * Some converters may need additional detection and may then set U_TRUNCATED_CHAR_FOUND.
+ *
+ * The toUnicodeWithOffsets must write exactly as many offset values as target
+ * units. Write offset values of -1 for when the source index corresponding to
+ * the output unit is not known (e.g., the character started in an earlier buffer).
+ * The pArgs->offsets pointer need not be moved forward.
+ *
+ * At function return, either one of the following conditions must be true:
+ * - U_BUFFER_OVERFLOW_ERROR and the target is full: target==targetLimit
+ * - another error code with toUBytes[toULength] set to the offending input
+ * - no error, and the source is consumed: source==sourceLimit
+ *
+ * The ucnv.c code will handle the end of the input (reset)
+ * (reset, and truncation detection) and callbacks.
+ */
+typedef void (*UConverterToUnicode) (UConverterToUnicodeArgs *, UErrorCode *);
+
+/*
+ * Same rules as for UConverterToUnicode.
+ * A lead surrogate is kept in fromUChar32 across buffers, and if an error
+ * occurs, then the offending input code point must be put into fromUChar32
+ * as well.
+ */
+typedef void (*UConverterFromUnicode) (UConverterFromUnicodeArgs *, UErrorCode *);
+
+/*
+ * Converter implementation function for ucnv_convertEx(), for direct conversion
+ * between two charsets without pivoting through UTF-16.
+ * The rules are the same as for UConverterToUnicode and UConverterFromUnicode.
+ * In addition,
+ * - The toUnicode side must behave and keep state exactly like the
+ * UConverterToUnicode implementation for the same source charset.
+ * - A U_USING_DEFAULT_WARNING can be set to request to temporarily fall back
+ * to pivoting. When this function is called, the conversion framework makes
+ * sure that this warning is not set on input.
+ * - Continuing a partial match and flushing the toUnicode replay buffer
+ * are handled by pivoting, using the toUnicode and fromUnicode functions.
+ */
+typedef void (*UConverterConvert) (UConverterFromUnicodeArgs *pFromUArgs,
+ UConverterToUnicodeArgs *pToUArgs,
+ UErrorCode *pErrorCode);
+
+/*
+ * Converter implementation function for ucnv_getNextUChar().
+ * If the function pointer is NULL, then the toUnicode function will be used.
+ *
+ * Will be called at a character boundary (toULength==0).
+ * May return with
+ * - U_INDEX_OUTOFBOUNDS_ERROR if there was no output for the input
+ * (the return value will be ignored)
+ * - U_TRUNCATED_CHAR_FOUND or another error code (never U_BUFFER_OVERFLOW_ERROR!)
+ * with toUBytes[toULength] set to the offending input
+ * (the return value will be ignored)
+ * - return UCNV_GET_NEXT_UCHAR_USE_TO_U, without moving the source pointer,
+ * to indicate that the ucnv.c code shall call the toUnicode function instead
+ * - return a real code point result
+ *
+ * Unless UCNV_GET_NEXT_UCHAR_USE_TO_U is returned, the source bytes must be consumed.
+ *
+ * The ucnv.c code will handle the end of the input (reset)
+ * (except for truncation detection!) and callbacks.
+ */
+typedef UChar32 (*UConverterGetNextUChar) (UConverterToUnicodeArgs *, UErrorCode *);
+
+typedef void (*UConverterGetStarters)(const UConverter* converter,
+ UBool starters[256],
+ UErrorCode *pErrorCode);
+
+/* If this function pointer is null or if the function returns null
+ * the name field in static data struct should be returned by
+ * ucnv_getName() API function
+ */
+typedef const char * (*UConverterGetName) (const UConverter *cnv);
+
+/**
+ * Write the codepage substitution character.
+ * If this function is not set, then ucnv_cbFromUWriteSub() writes
+ * the substitution character from UConverter.
+ * For stateful converters, it is typically necessary to handle this
+ * specificially for the converter in order to properly maintain the state.
+ */
+typedef void (*UConverterWriteSub) (UConverterFromUnicodeArgs *pArgs, int32_t offsetIndex, UErrorCode *pErrorCode);
+
+/**
+ * For converter-specific safeClone processing
+ * If this function is not set, then ucnv_safeClone assumes that the converter has no private data that changes
+ * after the converter is done opening.
+ * If this function is set, then it is called just after a memcpy() of
+ * converter data to the new, empty converter, and is expected to set up
+ * the initial state of the converter. It is not expected to increment the
+ * reference counts of the standard data types such as the shared data.
+ */
+typedef UConverter * (*UConverterSafeClone) (const UConverter *cnv,
+ void *stackBuffer,
+ int32_t *pBufferSize,
+ UErrorCode *status);
+
+/**
+ * Fills the set of Unicode code points that can be converted by an ICU converter.
+ * The API function ucnv_getUnicodeSet() clears the USet before calling
+ * the converter's getUnicodeSet() implementation; the converter should only
+ * add the appropriate code points to allow recursive use.
+ * For example, the ISO-2022-JP converter will call each subconverter's
+ * getUnicodeSet() implementation to consecutively add code points to
+ * the same USet, which will result in a union of the sets of all subconverters.
+ *
+ * For more documentation, see ucnv_getUnicodeSet() in ucnv.h.
+ */
+typedef void (*UConverterGetUnicodeSet) (const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode);
+
+UBool CONVERSION_U_SUCCESS (UErrorCode err);
+
+/**
+ * UConverterImpl contains all the data and functions for a converter type.
+ * Its function pointers work much like a C++ vtable.
+ * Many converter types need to define only a subset of the functions;
+ * when a function pointer is NULL, then a default action will be performed.
+ *
+ * Every converter type must implement toUnicode, fromUnicode, and getNextUChar,
+ * otherwise the converter may crash.
+ * Every converter type that has variable-length codepage sequences should
+ * also implement toUnicodeWithOffsets and fromUnicodeWithOffsets for
+ * correct offset handling.
+ * All other functions may or may not be implemented - it depends only on
+ * whether the converter type needs them.
+ *
+ * When open() fails, then close() will be called, if present.
+ */
+struct UConverterImpl {
+ UConverterType type;
+
+ UConverterLoad load;
+ UConverterUnload unload;
+
+ UConverterOpen open;
+ UConverterClose close;
+ UConverterReset reset;
+
+ UConverterToUnicode toUnicode;
+ UConverterToUnicode toUnicodeWithOffsets;
+ UConverterFromUnicode fromUnicode;
+ UConverterFromUnicode fromUnicodeWithOffsets;
+ UConverterGetNextUChar getNextUChar;
+
+ UConverterGetStarters getStarters;
+ UConverterGetName getName;
+ UConverterWriteSub writeSub;
+ UConverterSafeClone safeClone;
+ UConverterGetUnicodeSet getUnicodeSet;
+
+ UConverterConvert toUTF8;
+ UConverterConvert fromUTF8;
+};
+
+extern const UConverterSharedData
+ _MBCSData, _Latin1Data,
+ _UTF8Data, _UTF16BEData, _UTF16LEData, _UTF32BEData, _UTF32LEData,
+ _ISO2022Data,
+ _LMBCSData1,_LMBCSData2, _LMBCSData3, _LMBCSData4, _LMBCSData5, _LMBCSData6,
+ _LMBCSData8,_LMBCSData11,_LMBCSData16,_LMBCSData17,_LMBCSData18,_LMBCSData19,
+ _HZData,_ISCIIData, _SCSUData, _ASCIIData,
+ _UTF7Data, _Bocu1Data, _UTF16Data, _UTF32Data, _CESU8Data, _IMAPData;
+
+U_CDECL_END
+
+/** Always use fallbacks from codepage to Unicode */
+#define TO_U_USE_FALLBACK(useFallback) TRUE
+#define UCNV_TO_U_USE_FALLBACK(cnv) TRUE
+
+/** Use fallbacks from Unicode to codepage when cnv->useFallback or for private-use code points */
+#define IS_PRIVATE_USE(c) ((uint32_t)((c)-0xe000)<0x1900 || (uint32_t)((c)-0xf0000)<0x20000)
+#define FROM_U_USE_FALLBACK(useFallback, c) ((useFallback) || IS_PRIVATE_USE(c))
+#define UCNV_FROM_U_USE_FALLBACK(cnv, c) FROM_U_USE_FALLBACK((cnv)->useFallback, c)
+
+/**
+ * Magic number for ucnv_getNextUChar(), returned by a
+ * getNextUChar() implementation to indicate to use the converter's toUnicode()
+ * instead of the native function.
+ * @internal
+ */
+#define UCNV_GET_NEXT_UCHAR_USE_TO_U -9
+
+U_CFUNC void
+ucnv_getCompleteUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void
+ucnv_getNonSurrogateUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void
+ucnv_fromUWriteBytes(UConverter *cnv,
+ const char *bytes, int32_t length,
+ char **target, const char *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode);
+U_CFUNC void
+ucnv_toUWriteUChars(UConverter *cnv,
+ const UChar *uchars, int32_t length,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void
+ucnv_toUWriteCodePoint(UConverter *cnv,
+ UChar32 c,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets,
+ int32_t sourceIndex,
+ UErrorCode *pErrorCode);
+
+#endif
+
+#endif /* UCNV_CNV */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_err.c b/Build/source/libs/icu/icu-xetex/common/ucnv_err.c
new file mode 100644
index 00000000000..9b2c2852acd
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_err.c
@@ -0,0 +1,396 @@
+/*
+ *****************************************************************************
+ *
+ * Copyright (C) 1998-2007, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *
+ *****************************************************************************
+ *
+ * ucnv_err.c
+ * Implements error behaviour functions called by T_UConverter_{from,to}Unicode
+ *
+ *
+* Change history:
+*
+* 06/29/2000 helena Major rewrite of the callback APIs.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv_err.h"
+#include "unicode/ucnv_cb.h"
+#include "ucnv_cnv.h"
+#include "cmemory.h"
+#include "unicode/ucnv.h"
+#include "ustrfmt.h"
+
+#define VALUE_STRING_LENGTH 32
+/*Magic # 32 = 4(number of char in value string) * 8(max number of bytes per char for any converter) */
+#define UNICODE_PERCENT_SIGN_CODEPOINT 0x0025
+#define UNICODE_U_CODEPOINT 0x0055
+#define UNICODE_X_CODEPOINT 0x0058
+#define UNICODE_RS_CODEPOINT 0x005C
+#define UNICODE_U_LOW_CODEPOINT 0x0075
+#define UNICODE_X_LOW_CODEPOINT 0x0078
+#define UNICODE_AMP_CODEPOINT 0x0026
+#define UNICODE_HASH_CODEPOINT 0x0023
+#define UNICODE_SEMICOLON_CODEPOINT 0x003B
+#define UNICODE_PLUS_CODEPOINT 0x002B
+#define UNICODE_LEFT_CURLY_CODEPOINT 0x007B
+#define UNICODE_RIGHT_CURLY_CODEPOINT 0x007D
+#define UCNV_PRV_ESCAPE_ICU 0
+#define UCNV_PRV_ESCAPE_C 'C'
+#define UCNV_PRV_ESCAPE_XML_DEC 'D'
+#define UCNV_PRV_ESCAPE_XML_HEX 'X'
+#define UCNV_PRV_ESCAPE_JAVA 'J'
+#define UCNV_PRV_ESCAPE_UNICODE 'U'
+#define UCNV_PRV_STOP_ON_ILLEGAL 'i'
+
+/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
+U_CAPI void U_EXPORT2
+UCNV_FROM_U_CALLBACK_STOP (
+ const void *context,
+ UConverterFromUnicodeArgs *fromUArgs,
+ const UChar* codeUnits,
+ int32_t length,
+ UChar32 codePoint,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ /* the caller must have set the error code accordingly */
+ return;
+}
+
+
+/*Function Pointer STOPS at the ILLEGAL_SEQUENCE */
+U_CAPI void U_EXPORT2
+UCNV_TO_U_CALLBACK_STOP (
+ const void *context,
+ UConverterToUnicodeArgs *toUArgs,
+ const char* codePoints,
+ int32_t length,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ /* the caller must have set the error code accordingly */
+ return;
+}
+
+U_CAPI void U_EXPORT2
+UCNV_FROM_U_CALLBACK_SKIP (
+ const void *context,
+ UConverterFromUnicodeArgs *fromUArgs,
+ const UChar* codeUnits,
+ int32_t length,
+ UChar32 codePoint,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ if (reason <= UCNV_IRREGULAR)
+ {
+ if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
+ {
+ *err = U_ZERO_ERROR;
+ }
+ /* else the caller must have set the error code accordingly. */
+ }
+ /* else ignore the reset, close and clone calls. */
+}
+
+U_CAPI void U_EXPORT2
+UCNV_FROM_U_CALLBACK_SUBSTITUTE (
+ const void *context,
+ UConverterFromUnicodeArgs *fromArgs,
+ const UChar* codeUnits,
+ int32_t length,
+ UChar32 codePoint,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ if (reason <= UCNV_IRREGULAR)
+ {
+ if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
+ {
+ *err = U_ZERO_ERROR;
+ ucnv_cbFromUWriteSub(fromArgs, 0, err);
+ }
+ /* else the caller must have set the error code accordingly. */
+ }
+ /* else ignore the reset, close and clone calls. */
+}
+
+/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
+ *uses a clean copy (resetted) of the converter, to convert that unicode
+ *escape sequence to the target codepage (if conversion failure happens then
+ *we revert to substituting with subchar)
+ */
+U_CAPI void U_EXPORT2
+UCNV_FROM_U_CALLBACK_ESCAPE (
+ const void *context,
+ UConverterFromUnicodeArgs *fromArgs,
+ const UChar *codeUnits,
+ int32_t length,
+ UChar32 codePoint,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+
+ UChar valueString[VALUE_STRING_LENGTH];
+ int32_t valueStringLength = 0;
+ int32_t i = 0;
+
+ const UChar *myValueSource = NULL;
+ UErrorCode err2 = U_ZERO_ERROR;
+ UConverterFromUCallback original = NULL;
+ const void *originalContext;
+
+ UConverterFromUCallback ignoredCallback = NULL;
+ const void *ignoredContext;
+
+ if (reason > UCNV_IRREGULAR)
+ {
+ return;
+ }
+
+ ucnv_setFromUCallBack (fromArgs->converter,
+ (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE,
+ NULL,
+ &original,
+ &originalContext,
+ &err2);
+
+ if (U_FAILURE (err2))
+ {
+ *err = err2;
+ return;
+ }
+ if(context==NULL)
+ {
+ while (i < length)
+ {
+ valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
+ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
+ }
+ }
+ else
+ {
+ switch(*((char*)context))
+ {
+ case UCNV_PRV_ESCAPE_JAVA:
+ while (i < length)
+ {
+ valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
+ valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
+ }
+ break;
+
+ case UCNV_PRV_ESCAPE_C:
+ valueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
+
+ if(length==2){
+ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 8);
+
+ }
+ else{
+ valueString[valueStringLength++] = (UChar) UNICODE_U_LOW_CODEPOINT; /* adding u */
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4);
+ }
+ break;
+
+ case UCNV_PRV_ESCAPE_XML_DEC:
+
+ valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
+ valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
+ if(length==2){
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 10, 0);
+ }
+ else{
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 10, 0);
+ }
+ valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
+ break;
+
+ case UCNV_PRV_ESCAPE_XML_HEX:
+
+ valueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
+ valueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
+ valueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
+ if(length==2){
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 0);
+ }
+ else{
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 0);
+ }
+ valueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
+ break;
+
+ case UCNV_PRV_ESCAPE_UNICODE:
+ valueString[valueStringLength++] = (UChar) UNICODE_LEFT_CURLY_CODEPOINT; /* adding { */
+ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
+ valueString[valueStringLength++] = (UChar) UNICODE_PLUS_CODEPOINT; /* adding + */
+ if (length == 2) {
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, codePoint, 16, 4);
+ } else {
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[0], 16, 4);
+ }
+ valueString[valueStringLength++] = (UChar) UNICODE_RIGHT_CURLY_CODEPOINT; /* adding } */
+ break;
+
+ default:
+ while (i < length)
+ {
+ valueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
+ valueString[valueStringLength++] = (UChar) UNICODE_U_CODEPOINT; /* adding U */
+ valueStringLength += uprv_itou (valueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint16_t)codeUnits[i++], 16, 4);
+ }
+ }
+ }
+ myValueSource = valueString;
+
+ /* reset the error */
+ *err = U_ZERO_ERROR;
+
+ ucnv_cbFromUWriteUChars(fromArgs, &myValueSource, myValueSource+valueStringLength, 0, err);
+
+ ucnv_setFromUCallBack (fromArgs->converter,
+ original,
+ originalContext,
+ &ignoredCallback,
+ &ignoredContext,
+ &err2);
+ if (U_FAILURE (err2))
+ {
+ *err = err2;
+ return;
+ }
+
+ return;
+}
+
+
+
+U_CAPI void U_EXPORT2
+UCNV_TO_U_CALLBACK_SKIP (
+ const void *context,
+ UConverterToUnicodeArgs *toArgs,
+ const char* codeUnits,
+ int32_t length,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ if (reason <= UCNV_IRREGULAR)
+ {
+ if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
+ {
+ *err = U_ZERO_ERROR;
+ }
+ /* else the caller must have set the error code accordingly. */
+ }
+ /* else ignore the reset, close and clone calls. */
+}
+
+U_CAPI void U_EXPORT2
+UCNV_TO_U_CALLBACK_SUBSTITUTE (
+ const void *context,
+ UConverterToUnicodeArgs *toArgs,
+ const char* codeUnits,
+ int32_t length,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ if (reason <= UCNV_IRREGULAR)
+ {
+ if (context == NULL || (*((char*)context) == UCNV_PRV_STOP_ON_ILLEGAL && reason == UCNV_UNASSIGNED))
+ {
+ *err = U_ZERO_ERROR;
+ ucnv_cbToUWriteSub(toArgs,0,err);
+ }
+ /* else the caller must have set the error code accordingly. */
+ }
+ /* else ignore the reset, close and clone calls. */
+}
+
+/*uses uprv_itou to get a unicode escape sequence of the offensive sequence,
+ *and uses that as the substitution sequence
+ */
+U_CAPI void U_EXPORT2
+UCNV_TO_U_CALLBACK_ESCAPE (
+ const void *context,
+ UConverterToUnicodeArgs *toArgs,
+ const char* codeUnits,
+ int32_t length,
+ UConverterCallbackReason reason,
+ UErrorCode * err)
+{
+ UChar uniValueString[VALUE_STRING_LENGTH];
+ int32_t valueStringLength = 0;
+ int32_t i = 0;
+
+ if (reason > UCNV_IRREGULAR)
+ {
+ return;
+ }
+
+ if(context==NULL)
+ {
+ while (i < length)
+ {
+ uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */
+ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
+ }
+ }
+ else
+ {
+ switch(*((char*)context))
+ {
+ case UCNV_PRV_ESCAPE_XML_DEC:
+ while (i < length)
+ {
+ uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
+ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 10, 0);
+ uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
+ }
+ break;
+
+ case UCNV_PRV_ESCAPE_XML_HEX:
+ while (i < length)
+ {
+ uniValueString[valueStringLength++] = (UChar) UNICODE_AMP_CODEPOINT; /* adding & */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_HASH_CODEPOINT; /* adding # */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
+ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 0);
+ uniValueString[valueStringLength++] = (UChar) UNICODE_SEMICOLON_CODEPOINT; /* adding ; */
+ }
+ break;
+ case UCNV_PRV_ESCAPE_C:
+ while (i < length)
+ {
+ uniValueString[valueStringLength++] = (UChar) UNICODE_RS_CODEPOINT; /* adding \ */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_X_LOW_CODEPOINT; /* adding x */
+ valueStringLength += uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t)codeUnits[i++], 16, 2);
+ }
+ break;
+ default:
+ while (i < length)
+ {
+ uniValueString[valueStringLength++] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
+ uniValueString[valueStringLength++] = (UChar) UNICODE_X_CODEPOINT; /* adding X */
+ uprv_itou (uniValueString + valueStringLength, VALUE_STRING_LENGTH - valueStringLength, (uint8_t) codeUnits[i++], 16, 2);
+ valueStringLength += 2;
+ }
+ }
+ }
+ /* reset the error */
+ *err = U_ZERO_ERROR;
+
+ ucnv_cbToUWriteUChars(toArgs, uniValueString, valueStringLength, 0, err);
+}
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_ext.c b/Build/source/libs/icu/icu-xetex/common/ucnv_ext.c
new file mode 100644
index 00000000000..d60127fc89a
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_ext.c
@@ -0,0 +1,1088 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2003-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ucnv_ext.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2003jun13
+* created by: Markus W. Scherer
+*
+* Conversion extensions
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION
+
+#include "unicode/uset.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+#include "ucnv_ext.h"
+#include "cmemory.h"
+
+/* to Unicode --------------------------------------------------------------- */
+
+/*
+ * @return lookup value for the byte, if found; else 0
+ */
+static U_INLINE uint32_t
+ucnv_extFindToU(const uint32_t *toUSection, int32_t length, uint8_t byte) {
+ uint32_t word0, word;
+ int32_t i, start, limit;
+
+ /* check the input byte against the lowest and highest section bytes */
+ start=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[0]);
+ limit=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[length-1]);
+ if(byte1) {
+ return 0; /* no match of a DBCS sequence in SBCS mode */
+ } else if(preLength==1) {
+ srcLength=0;
+ } else /* preLength==0 */ {
+ if(srcLength>1) {
+ srcLength=1;
+ }
+ }
+ flush=TRUE;
+ }
+
+ /* we must not remember fallback matches when not using fallbacks */
+
+ /* match input units until there is a full match or the input is consumed */
+ for(;;) {
+ /* go to the next section */
+ toUSection=toUTable+index;
+
+ /* read first pair of the section */
+ value=*toUSection++;
+ length=UCNV_EXT_TO_U_GET_BYTE(value);
+ value=UCNV_EXT_TO_U_GET_VALUE(value);
+ if( value!=0 &&
+ (UCNV_EXT_TO_U_IS_ROUNDTRIP(value) ||
+ TO_U_USE_FALLBACK(useFallback)) &&
+ UCNV_EXT_TO_U_VERIFY_SISO_MATCH(sisoState, i+j)
+ ) {
+ /* remember longest match so far */
+ matchValue=value;
+ matchLength=i+j;
+ }
+
+ /* match pre[] then src[] */
+ if(iUCNV_EXT_MAX_BYTES) {
+ /*
+ * end of the entire input stream, stop with the longest match so far
+ * or: partial match must not be longer than UCNV_EXT_MAX_BYTES
+ * because it must fit into state buffers
+ */
+ break;
+ } else {
+ /* continue with more input next time */
+ return -length;
+ }
+ }
+
+ /* search for the current UChar */
+ value=ucnv_extFindToU(toUSection, length, b);
+ if(value==0) {
+ /* no match here, stop with the longest match so far */
+ break;
+ } else {
+ if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
+ /* partial match, continue */
+ index=(int32_t)UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value);
+ } else {
+ if( (UCNV_EXT_TO_U_IS_ROUNDTRIP(value) ||
+ TO_U_USE_FALLBACK(useFallback)) &&
+ UCNV_EXT_TO_U_VERIFY_SISO_MATCH(sisoState, i+j)
+ ) {
+ /* full match, stop with result */
+ matchValue=value;
+ matchLength=i+j;
+ } else {
+ /* full match on fallback not taken, stop with the longest match so far */
+ }
+ break;
+ }
+ }
+ }
+
+ if(matchLength==0) {
+ /* no match at all */
+ return 0;
+ }
+
+ /* return result */
+ *pMatchValue=UCNV_EXT_TO_U_MASK_ROUNDTRIP(matchValue);
+ return matchLength;
+}
+
+static U_INLINE void
+ucnv_extWriteToU(UConverter *cnv, const int32_t *cx,
+ uint32_t value,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets, int32_t srcIndex,
+ UErrorCode *pErrorCode) {
+ /* output the result */
+ if(UCNV_EXT_TO_U_IS_CODE_POINT(value)) {
+ /* output a single code point */
+ ucnv_toUWriteCodePoint(
+ cnv, UCNV_EXT_TO_U_GET_CODE_POINT(value),
+ target, targetLimit,
+ offsets, srcIndex,
+ pErrorCode);
+ } else {
+ /* output a string - with correct data we have resultLength>0 */
+ ucnv_toUWriteUChars(
+ cnv,
+ UCNV_EXT_ARRAY(cx, UCNV_EXT_TO_U_UCHARS_INDEX, UChar)+
+ UCNV_EXT_TO_U_GET_INDEX(value),
+ UCNV_EXT_TO_U_GET_LENGTH(value),
+ target, targetLimit,
+ offsets, srcIndex,
+ pErrorCode);
+ }
+}
+
+/*
+ * get the SI/SO toU state (state 0 is for SBCS, 1 for DBCS),
+ * or 1 for DBCS-only,
+ * or -1 if the converter is not SI/SO stateful
+ *
+ * Note: For SI/SO stateful converters getting here,
+ * cnv->mode==0 is equivalent to firstLength==1.
+ */
+#define UCNV_SISO_STATE(cnv) \
+ ((cnv)->sharedData->mbcs.outputType==MBCS_OUTPUT_2_SISO ? (int8_t)(cnv)->mode : \
+ (cnv)->sharedData->mbcs.outputType==MBCS_OUTPUT_DBCS_ONLY ? 1 : -1)
+
+/*
+ * targettoUBytes, firstLength,
+ *src, (int32_t)(srcLimit-*src),
+ &value,
+ cnv->useFallback, flush);
+ if(match>0) {
+ /* advance src pointer for the consumed input */
+ *src+=match-firstLength;
+
+ /* write result to target */
+ ucnv_extWriteToU(cnv, cx,
+ value,
+ target, targetLimit,
+ offsets, srcIndex,
+ pErrorCode);
+ return TRUE;
+ } else if(match<0) {
+ /* save state for partial match */
+ const char *s;
+ int32_t j;
+
+ /* copy the first code point */
+ s=(const char *)cnv->toUBytes;
+ cnv->preToUFirstLength=(int8_t)firstLength;
+ for(j=0; jpreToU[j]=*s++;
+ }
+
+ /* now copy the newly consumed input */
+ s=*src;
+ match=-match;
+ for(; jpreToU[j]=*s++;
+ }
+ *src=s; /* same as *src=srcLimit; because we reached the end of input */
+ cnv->preToULength=(int8_t)match;
+ return TRUE;
+ } else /* match==0 no match */ {
+ return FALSE;
+ }
+}
+
+U_CFUNC UChar32
+ucnv_extSimpleMatchToU(const int32_t *cx,
+ const char *source, int32_t length,
+ UBool useFallback) {
+ uint32_t value;
+ int32_t match;
+
+ if(length<=0) {
+ return 0xffff;
+ }
+
+ /* try to match */
+ match=ucnv_extMatchToU(cx, -1,
+ source, length,
+ NULL, 0,
+ &value,
+ useFallback, TRUE);
+ if(match==length) {
+ /* write result for simple, single-character conversion */
+ if(UCNV_EXT_TO_U_IS_CODE_POINT(value)) {
+ return UCNV_EXT_TO_U_GET_CODE_POINT(value);
+ }
+ }
+
+ /*
+ * return no match because
+ * - match>0 && value points to string: simple conversion cannot handle multiple code points
+ * - match>0 && match!=length: not all input consumed, forbidden for this function
+ * - match==0: no match found in the first place
+ * - match<0: partial match, not supported for simple conversion (and flush==TRUE)
+ */
+ return 0xfffe;
+}
+
+/*
+ * continue partial match with new input
+ * never called for simple, single-character conversion
+ */
+U_CFUNC void
+ucnv_extContinueMatchToU(UConverter *cnv,
+ UConverterToUnicodeArgs *pArgs, int32_t srcIndex,
+ UErrorCode *pErrorCode) {
+ uint32_t value;
+ int32_t match, length;
+
+ match=ucnv_extMatchToU(cnv->sharedData->mbcs.extIndexes, (int8_t)UCNV_SISO_STATE(cnv),
+ cnv->preToU, cnv->preToULength,
+ pArgs->source, (int32_t)(pArgs->sourceLimit-pArgs->source),
+ &value,
+ cnv->useFallback, pArgs->flush);
+ if(match>0) {
+ if(match>=cnv->preToULength) {
+ /* advance src pointer for the consumed input */
+ pArgs->source+=match-cnv->preToULength;
+ cnv->preToULength=0;
+ } else {
+ /* the match did not use all of preToU[] - keep the rest for replay */
+ length=cnv->preToULength-match;
+ uprv_memmove(cnv->preToU, cnv->preToU+match, length);
+ cnv->preToULength=(int8_t)-length;
+ }
+
+ /* write result */
+ ucnv_extWriteToU(cnv, cnv->sharedData->mbcs.extIndexes,
+ value,
+ &pArgs->target, pArgs->targetLimit,
+ &pArgs->offsets, srcIndex,
+ pErrorCode);
+ } else if(match<0) {
+ /* save state for partial match */
+ const char *s;
+ int32_t j;
+
+ /* just _append_ the newly consumed input to preToU[] */
+ s=pArgs->source;
+ match=-match;
+ for(j=cnv->preToULength; jpreToU[j]=*s++;
+ }
+ pArgs->source=s; /* same as *src=srcLimit; because we reached the end of input */
+ cnv->preToULength=(int8_t)match;
+ } else /* match==0 */ {
+ /*
+ * no match
+ *
+ * We need to split the previous input into two parts:
+ *
+ * 1. The first codepage character is unmappable - that's how we got into
+ * trying the extension data in the first place.
+ * We need to move it from the preToU buffer
+ * to the error buffer, set an error code,
+ * and prepare the rest of the previous input for 2.
+ *
+ * 2. The rest of the previous input must be converted once we
+ * come back from the callback for the first character.
+ * At that time, we have to try again from scratch to convert
+ * these input characters.
+ * The replay will be handled by the ucnv.c conversion code.
+ */
+
+ /* move the first codepage character to the error field */
+ uprv_memcpy(cnv->toUBytes, cnv->preToU, cnv->preToUFirstLength);
+ cnv->toULength=cnv->preToUFirstLength;
+
+ /* move the rest up inside the buffer */
+ length=cnv->preToULength-cnv->preToUFirstLength;
+ if(length>0) {
+ uprv_memmove(cnv->preToU, cnv->preToU+cnv->preToUFirstLength, length);
+ }
+
+ /* mark preToU for replay */
+ cnv->preToULength=(int8_t)-length;
+
+ /* set the error code for unassigned */
+ *pErrorCode=U_INVALID_CHAR_FOUND;
+ }
+}
+
+/* from Unicode ------------------------------------------------------------- */
+
+/*
+ * @return index of the UChar, if found; else <0
+ */
+static U_INLINE int32_t
+ucnv_extFindFromU(const UChar *fromUSection, int32_t length, UChar u) {
+ int32_t i, start, limit;
+
+ /* binary search */
+ start=0;
+ limit=length;
+ for(;;) {
+ i=limit-start;
+ if(i<=1) {
+ break; /* done */
+ }
+ /* start=0
+ * @param src UChars that can be used to complete a match
+ * @param srcLength length of src, >=0
+ * @param pMatchValue [out] output result value for the match from the data structure
+ * @param useFallback "use fallback" flag, usually from cnv->useFallback
+ * @param flush TRUE if the end of the input stream is reached
+ * @return >1: matched, return value=total match length (number of input units matched)
+ * 1: matched, no mapping but request for
+ * (only for the first code point)
+ * 0: no match
+ * <0: partial match, return value=negative total match length
+ * (partial matches are never returned for flush==TRUE)
+ * (partial matches are never returned as being longer than UCNV_EXT_MAX_UCHARS)
+ * the matchLength is 2 if only firstCP matched, and >2 if firstCP and
+ * further code units matched
+ */
+static int32_t
+ucnv_extMatchFromU(const int32_t *cx,
+ UChar32 firstCP,
+ const UChar *pre, int32_t preLength,
+ const UChar *src, int32_t srcLength,
+ uint32_t *pMatchValue,
+ UBool useFallback, UBool flush) {
+ const uint16_t *stage12, *stage3;
+ const uint32_t *stage3b;
+
+ const UChar *fromUTableUChars, *fromUSectionUChars;
+ const uint32_t *fromUTableValues, *fromUSectionValues;
+
+ uint32_t value, matchValue;
+ int32_t i, j, index, length, matchLength;
+ UChar c;
+
+ if(cx==NULL) {
+ return 0; /* no extension data, no match */
+ }
+
+ /* trie lookup of firstCP */
+ index=firstCP>>10; /* stage 1 index */
+ if(index>=cx[UCNV_EXT_FROM_U_STAGE_1_LENGTH]) {
+ return 0; /* the first code point is outside the trie */
+ }
+
+ stage12=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_12_INDEX, uint16_t);
+ stage3=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_3_INDEX, uint16_t);
+ index=UCNV_EXT_FROM_U(stage12, stage3, index, firstCP);
+
+ stage3b=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_3B_INDEX, uint32_t);
+ value=stage3b[index];
+ if(value==0) {
+ return 0;
+ }
+
+ /*
+ * Tests for (value&UCNV_EXT_FROM_U_RESERVED_MASK)==0:
+ * Do not interpret values with reserved bits used, for forward compatibility,
+ * and do not even remember intermediate results with reserved bits used.
+ */
+
+ if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
+ /* partial match, enter the loop below */
+ index=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value);
+
+ /* initialize */
+ fromUTableUChars=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_UCHARS_INDEX, UChar);
+ fromUTableValues=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_VALUES_INDEX, uint32_t);
+
+ matchValue=0;
+ i=j=matchLength=0;
+
+ /* we must not remember fallback matches when not using fallbacks */
+
+ /* match input units until there is a full match or the input is consumed */
+ for(;;) {
+ /* go to the next section */
+ fromUSectionUChars=fromUTableUChars+index;
+ fromUSectionValues=fromUTableValues+index;
+
+ /* read first pair of the section */
+ length=*fromUSectionUChars++;
+ value=*fromUSectionValues++;
+ if( value!=0 &&
+ (UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) ||
+ FROM_U_USE_FALLBACK(useFallback, firstCP)) &&
+ (value&UCNV_EXT_FROM_U_RESERVED_MASK)==0
+ ) {
+ /* remember longest match so far */
+ matchValue=value;
+ matchLength=2+i+j;
+ }
+
+ /* match pre[] then src[] */
+ if(iUCNV_EXT_MAX_UCHARS) {
+ /*
+ * end of the entire input stream, stop with the longest match so far
+ * or: partial match must not be longer than UCNV_EXT_MAX_UCHARS
+ * because it must fit into state buffers
+ */
+ break;
+ } else {
+ /* continue with more input next time */
+ return -(2+length);
+ }
+ }
+
+ /* search for the current UChar */
+ index=ucnv_extFindFromU(fromUSectionUChars, length, c);
+ if(index<0) {
+ /* no match here, stop with the longest match so far */
+ break;
+ } else {
+ value=fromUSectionValues[index];
+ if(UCNV_EXT_FROM_U_IS_PARTIAL(value)) {
+ /* partial match, continue */
+ index=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value);
+ } else {
+ if( (UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) ||
+ FROM_U_USE_FALLBACK(useFallback, firstCP)) &&
+ (value&UCNV_EXT_FROM_U_RESERVED_MASK)==0
+ ) {
+ /* full match, stop with result */
+ matchValue=value;
+ matchLength=2+i+j;
+ } else {
+ /* full match on fallback not taken, stop with the longest match so far */
+ }
+ break;
+ }
+ }
+ }
+
+ if(matchLength==0) {
+ /* no match at all */
+ return 0;
+ }
+ } else /* result from firstCP trie lookup */ {
+ if( (UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) ||
+ FROM_U_USE_FALLBACK(useFallback, firstCP)) &&
+ (value&UCNV_EXT_FROM_U_RESERVED_MASK)==0
+ ) {
+ /* full match, stop with result */
+ matchValue=value;
+ matchLength=2;
+ } else {
+ /* fallback not taken */
+ return 0;
+ }
+ }
+
+ /* return result */
+ if(matchValue==UCNV_EXT_FROM_U_SUBCHAR1) {
+ return 1; /* assert matchLength==2 */
+ }
+
+ *pMatchValue=matchValue;
+ return matchLength;
+}
+
+/*
+ * @param value fromUnicode mapping table value; ignores roundtrip and reserved bits
+ */
+static U_INLINE void
+ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
+ uint32_t value,
+ char **target, const char *targetLimit,
+ int32_t **offsets, int32_t srcIndex,
+ UErrorCode *pErrorCode) {
+ uint8_t buffer[1+UCNV_EXT_MAX_BYTES];
+ const uint8_t *result;
+ int32_t length, prevLength;
+
+ length=UCNV_EXT_FROM_U_GET_LENGTH(value);
+ value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value);
+
+ /* output the result */
+ if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
+ /*
+ * Generate a byte array and then write it below.
+ * This is not the fastest possible way, but it should be ok for
+ * extension mappings, and it is much simpler.
+ * Offset and overflow handling are only done once this way.
+ */
+ uint8_t *p=buffer+1; /* reserve buffer[0] for shiftByte below */
+ switch(length) {
+ case 3:
+ *p++=(uint8_t)(value>>16);
+ case 2:
+ *p++=(uint8_t)(value>>8);
+ case 1:
+ *p++=(uint8_t)value;
+ default:
+ break; /* will never occur */
+ }
+ result=buffer+1;
+ } else {
+ result=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_BYTES_INDEX, uint8_t)+value;
+ }
+
+ /* with correct data we have length>0 */
+
+ if((prevLength=cnv->fromUnicodeStatus)!=0) {
+ /* handle SI/SO stateful output */
+ uint8_t shiftByte;
+
+ if(prevLength>1 && length==1) {
+ /* change from double-byte mode to single-byte */
+ shiftByte=(uint8_t)UCNV_SI;
+ cnv->fromUnicodeStatus=1;
+ } else if(prevLength==1 && length>1) {
+ /* change from single-byte mode to double-byte */
+ shiftByte=(uint8_t)UCNV_SO;
+ cnv->fromUnicodeStatus=2;
+ } else {
+ shiftByte=0;
+ }
+
+ if(shiftByte!=0) {
+ /* prepend the shift byte to the result bytes */
+ buffer[0]=shiftByte;
+ if(result!=buffer+1) {
+ uprv_memcpy(buffer+1, result, length);
+ }
+ result=buffer;
+ ++length;
+ }
+ }
+
+ ucnv_fromUWriteBytes(cnv, (const char *)result, length,
+ target, targetLimit,
+ offsets, srcIndex,
+ pErrorCode);
+}
+
+/*
+ * targetuseFallback, flush);
+
+ /* reject a match if the result is a single byte for DBCS-only */
+ if( match>=2 &&
+ !(UCNV_EXT_FROM_U_GET_LENGTH(value)==1 &&
+ cnv->sharedData->mbcs.outputType==MBCS_OUTPUT_DBCS_ONLY)
+ ) {
+ /* advance src pointer for the consumed input */
+ *src+=match-2; /* remove 2 for the initial code point */
+
+ /* write result to target */
+ ucnv_extWriteFromU(cnv, cx,
+ value,
+ target, targetLimit,
+ offsets, srcIndex,
+ pErrorCode);
+ return TRUE;
+ } else if(match<0) {
+ /* save state for partial match */
+ const UChar *s;
+ int32_t j;
+
+ /* copy the first code point */
+ cnv->preFromUFirstCP=cp;
+
+ /* now copy the newly consumed input */
+ s=*src;
+ match=-match-2; /* remove 2 for the initial code point */
+ for(j=0; jpreFromU[j]=*s++;
+ }
+ *src=s; /* same as *src=srcLimit; because we reached the end of input */
+ cnv->preFromULength=(int8_t)match;
+ return TRUE;
+ } else if(match==1) {
+ /* matched, no mapping but request for */
+ cnv->useSubChar1=TRUE;
+ return FALSE;
+ } else /* match==0 no match */ {
+ return FALSE;
+ }
+}
+
+/*
+ * Used by ISO 2022 implementation.
+ * @return number of bytes in *pValue; negative number if fallback; 0 for no mapping
+ */
+U_CFUNC int32_t
+ucnv_extSimpleMatchFromU(const int32_t *cx,
+ UChar32 cp, uint32_t *pValue,
+ UBool useFallback) {
+ uint32_t value;
+ int32_t match;
+
+ /* try to match */
+ match=ucnv_extMatchFromU(cx,
+ cp,
+ NULL, 0,
+ NULL, 0,
+ &value,
+ useFallback, TRUE);
+ if(match>=2) {
+ /* write result for simple, single-character conversion */
+ int32_t length;
+ int isRoundtrip;
+
+ isRoundtrip=UCNV_EXT_FROM_U_IS_ROUNDTRIP(value);
+ length=UCNV_EXT_FROM_U_GET_LENGTH(value);
+ value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value);
+
+ if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
+ *pValue=value;
+ return isRoundtrip ? length : -length;
+#if 0 /* not currently used */
+ } else if(length==4) {
+ /* de-serialize a 4-byte result */
+ const uint8_t *result=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_BYTES_INDEX, uint8_t)+value;
+ *pValue=
+ ((uint32_t)result[0]<<24)|
+ ((uint32_t)result[1]<<16)|
+ ((uint32_t)result[2]<<8)|
+ result[3];
+ return isRoundtrip ? 4 : -4;
+#endif
+ }
+ }
+
+ /*
+ * return no match because
+ * - match>1 && resultLength>4: result too long for simple conversion
+ * - match==1: no match found, preferred
+ * - match==0: no match found in the first place
+ * - match<0: partial match, not supported for simple conversion (and flush==TRUE)
+ */
+ return 0;
+}
+
+/*
+ * continue partial match with new input, requires cnv->preFromUFirstCP>=0
+ * never called for simple, single-character conversion
+ */
+U_CFUNC void
+ucnv_extContinueMatchFromU(UConverter *cnv,
+ UConverterFromUnicodeArgs *pArgs, int32_t srcIndex,
+ UErrorCode *pErrorCode) {
+ uint32_t value;
+ int32_t match;
+
+ match=ucnv_extMatchFromU(cnv->sharedData->mbcs.extIndexes,
+ cnv->preFromUFirstCP,
+ cnv->preFromU, cnv->preFromULength,
+ pArgs->source, (int32_t)(pArgs->sourceLimit-pArgs->source),
+ &value,
+ cnv->useFallback, pArgs->flush);
+ if(match>=2) {
+ match-=2; /* remove 2 for the initial code point */
+
+ if(match>=cnv->preFromULength) {
+ /* advance src pointer for the consumed input */
+ pArgs->source+=match-cnv->preFromULength;
+ cnv->preFromULength=0;
+ } else {
+ /* the match did not use all of preFromU[] - keep the rest for replay */
+ int32_t length=cnv->preFromULength-match;
+ uprv_memmove(cnv->preFromU, cnv->preFromU+match, length*U_SIZEOF_UCHAR);
+ cnv->preFromULength=(int8_t)-length;
+ }
+
+ /* finish the partial match */
+ cnv->preFromUFirstCP=U_SENTINEL;
+
+ /* write result */
+ ucnv_extWriteFromU(cnv, cnv->sharedData->mbcs.extIndexes,
+ value,
+ &pArgs->target, pArgs->targetLimit,
+ &pArgs->offsets, srcIndex,
+ pErrorCode);
+ } else if(match<0) {
+ /* save state for partial match */
+ const UChar *s;
+ int32_t j;
+
+ /* just _append_ the newly consumed input to preFromU[] */
+ s=pArgs->source;
+ match=-match-2; /* remove 2 for the initial code point */
+ for(j=cnv->preFromULength; jpreFromU[j]=*s++;
+ }
+ pArgs->source=s; /* same as *src=srcLimit; because we reached the end of input */
+ cnv->preFromULength=(int8_t)match;
+ } else /* match==0 or 1 */ {
+ /*
+ * no match
+ *
+ * We need to split the previous input into two parts:
+ *
+ * 1. The first code point is unmappable - that's how we got into
+ * trying the extension data in the first place.
+ * We need to move it from the preFromU buffer
+ * to the error buffer, set an error code,
+ * and prepare the rest of the previous input for 2.
+ *
+ * 2. The rest of the previous input must be converted once we
+ * come back from the callback for the first code point.
+ * At that time, we have to try again from scratch to convert
+ * these input characters.
+ * The replay will be handled by the ucnv.c conversion code.
+ */
+
+ if(match==1) {
+ /* matched, no mapping but request for */
+ cnv->useSubChar1=TRUE;
+ }
+
+ /* move the first code point to the error field */
+ cnv->fromUChar32=cnv->preFromUFirstCP;
+ cnv->preFromUFirstCP=U_SENTINEL;
+
+ /* mark preFromU for replay */
+ cnv->preFromULength=-cnv->preFromULength;
+
+ /* set the error code for unassigned */
+ *pErrorCode=U_INVALID_CHAR_FOUND;
+ }
+}
+
+static void
+ucnv_extGetUnicodeSetString(const UConverterSharedData *sharedData,
+ const int32_t *cx,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ int32_t minLength,
+ UChar32 c,
+ UChar s[UCNV_EXT_MAX_UCHARS], int32_t length,
+ int32_t sectionIndex,
+ UErrorCode *pErrorCode) {
+ const UChar *fromUSectionUChars;
+ const uint32_t *fromUSectionValues;
+
+ uint32_t value;
+ int32_t i, count;
+
+ fromUSectionUChars=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_UCHARS_INDEX, UChar)+sectionIndex;
+ fromUSectionValues=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_VALUES_INDEX, uint32_t)+sectionIndex;
+
+ /* read first pair of the section */
+ count=*fromUSectionUChars++;
+ value=*fromUSectionValues++;
+
+ if( value!=0 &&
+ UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) &&
+ UCNV_EXT_FROM_U_GET_LENGTH(value)>=minLength
+ ) {
+ if(c>=0) {
+ /* add the initial code point */
+ sa->add(sa->set, c);
+ } else {
+ /* add the string so far */
+ sa->addString(sa->set, s, length);
+ }
+ }
+
+ for(i=0; i=minLength
+ ) {
+ sa->addString(sa->set, s, length+1);
+ }
+ }
+}
+
+U_CFUNC void
+ucnv_extGetUnicodeSet(const UConverterSharedData *sharedData,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode) {
+ const int32_t *cx;
+ const uint16_t *stage12, *stage3, *ps2, *ps3;
+ const uint32_t *stage3b;
+
+ uint32_t value;
+ int32_t st1, stage1Length, st2, st3, minLength;
+
+ UChar s[UCNV_EXT_MAX_UCHARS];
+ UChar32 c;
+ int32_t length;
+
+ cx=sharedData->mbcs.extIndexes;
+ if(cx==NULL) {
+ return;
+ }
+
+ stage12=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_12_INDEX, uint16_t);
+ stage3=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_3_INDEX, uint16_t);
+ stage3b=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_STAGE_3B_INDEX, uint32_t);
+
+ stage1Length=cx[UCNV_EXT_FROM_U_STAGE_1_LENGTH];
+
+ /* enumerate the from-Unicode trie table */
+ c=0; /* keep track of the current code point while enumerating */
+
+ if(sharedData->mbcs.outputType==MBCS_OUTPUT_DBCS_ONLY) {
+ /* DBCS-only, ignore single-byte results */
+ minLength=2;
+ } else {
+ minLength=1;
+ }
+
+ /*
+ * the trie enumeration is almost the same as
+ * in MBCSGetUnicodeSet() for MBCS_OUTPUT_1
+ */
+ for(st1=0; st1stage1Length) {
+ ps2=stage12+st2;
+ for(st2=0; st2<64; ++st2) {
+ if((st3=(int32_t)ps2[st2]< entries or other (future?) pseudo-entries
+ * with an output length of 0, or entries with reserved bits set.
+ * Recurse for partial results.
+ */
+ do {
+ value=stage3b[*ps3++];
+ if(value==0) {
+ /* no mapping, do nothing */
+ } else if(UCNV_EXT_FROM_U_IS_PARTIAL(value)) {
+ length=0;
+ U16_APPEND_UNSAFE(s, length, c);
+ ucnv_extGetUnicodeSetString(
+ sharedData, cx, sa, which, minLength,
+ c, s, length,
+ (int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value),
+ pErrorCode);
+ } else if(((value&(UCNV_EXT_FROM_U_ROUNDTRIP_FLAG|UCNV_EXT_FROM_U_RESERVED_MASK))==
+ UCNV_EXT_FROM_U_ROUNDTRIP_FLAG) &&
+ UCNV_EXT_FROM_U_GET_LENGTH(value)>=minLength
+ ) {
+ sa->add(sa->set, c);
+ }
+ } while((++c&0xf)!=0);
+ } else {
+ c+=16; /* empty stage 3 block */
+ }
+ }
+ } else {
+ c+=1024; /* empty stage 2 block */
+ }
+ }
+}
+
+#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_ext.h b/Build/source/libs/icu/icu-xetex/common/ucnv_ext.h
new file mode 100644
index 00000000000..c90fcf6ab8a
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_ext.h
@@ -0,0 +1,463 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 2003-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: ucnv_ext.h
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2003jun13
+* created by: Markus W. Scherer
+*
+* Conversion extensions
+*/
+
+#ifndef __UCNV_EXT_H__
+#define __UCNV_EXT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "ucnv_cnv.h"
+
+/*
+ * See icuhtml/design/conversion/conversion_extensions.html
+ *
+ * Conversion extensions serve two purposes:
+ * 1. They support m:n mappings.
+ * 2. They support extension-only conversion files that are used together
+ * with the regular conversion data in base files.
+ *
+ * A base file may contain an extension table (explicitly requested or
+ * implicitly generated for m:n mappings), but its extension table is not
+ * used when an extension-only file is used.
+ *
+ * It is an error if a base file contains any regular (not extension) mapping
+ * from the same sequence as a mapping in the extension file
+ * because the base mapping would hide the extension mapping.
+ *
+ *
+ * Data for conversion extensions:
+ *
+ * One set of data structures per conversion direction (to/from Unicode).
+ * The data structures are sorted by input units to allow for binary search.
+ * Input sequences of more than one unit are handled like contraction tables
+ * in collation:
+ * The lookup value of a unit points to another table that is to be searched
+ * for the next unit, recursively.
+ *
+ * For conversion from Unicode, the initial code point is looked up in
+ * a 3-stage trie for speed,
+ * with an additional table of unique results to save space.
+ *
+ * Long output strings are stored in separate arrays, with length and index
+ * in the lookup tables.
+ * Output results also include a flag distinguishing roundtrip from
+ * (reverse) fallback mappings.
+ *
+ * Input Unicode strings must not begin or end with unpaired surrogates
+ * to avoid problems with matches on parts of surrogate pairs.
+ *
+ * Mappings from multiple characters (code points or codepage state
+ * table sequences) must be searched preferring the longest match.
+ * For this to work and be efficient, the variable-width table must contain
+ * all mappings that contain prefixes of the multiple characters.
+ * If an extension table is built on top of a base table in another file
+ * and a base table entry is a prefix of a multi-character mapping, then
+ * this is an error.
+ *
+ *
+ * Implementation note:
+ *
+ * Currently, the parser and several checks in the code limit the number
+ * of UChars or bytes in a mapping to
+ * UCNV_EXT_MAX_UCHARS and UCNV_EXT_MAX_BYTES, respectively,
+ * which are output value limits in the data structure.
+ *
+ * For input, this is not strictly necessary - it is a hard limit only for the
+ * buffers in UConverter that are used to store partial matches.
+ *
+ * Input sequences could otherwise be arbitrarily long if partial matches
+ * need not be stored (i.e., if a sequence does not span several buffers with too
+ * many units before the last buffer), although then results would differ
+ * depending on whether partial matches exceed the limits or not,
+ * which depends on the pattern of buffer sizes.
+ *
+ *
+ * Data structure:
+ *
+ * int32_t indexes[>=32];
+ *
+ * Array of indexes and lengths etc. The length of the array is at least 32.
+ * The actual length is stored in indexes[0] to be forward compatible.
+ *
+ * Each index to another array is the number of bytes from indexes[].
+ * Each length of an array is the number of array base units in that array.
+ *
+ * Some of the structures may not be present, in which case their indexes
+ * and lengths are 0.
+ *
+ * Usage of indexes[i]:
+ * [0] length of indexes[]
+ *
+ * // to Unicode table
+ * [1] index of toUTable[] (array of uint32_t)
+ * [2] length of toUTable[]
+ * [3] index of toUUChars[] (array of UChar)
+ * [4] length of toUUChars[]
+ *
+ * // from Unicode table, not for the initial code point
+ * [5] index of fromUTableUChars[] (array of UChar)
+ * [6] index of fromUTableValues[] (array of uint32_t)
+ * [7] length of fromUTableUChars[] and fromUTableValues[]
+ * [8] index of fromUBytes[] (array of char)
+ * [9] length of fromUBytes[]
+ *
+ * // from Unicode trie for initial-code point lookup
+ * [10] index of fromUStage12[] (combined array of uint16_t for stages 1 & 2)
+ * [11] length of stage 1 portion of fromUStage12[]
+ * [12] length of fromUStage12[]
+ * [13] index of fromUStage3[] (array of uint16_t indexes into fromUStage3b[])
+ * [14] length of fromUStage3[]
+ * [15] index of fromUStage3b[] (array of uint32_t like fromUTableValues[])
+ * [16] length of fromUStage3b[]
+ *
+ * [17] Bit field containing numbers of bytes:
+ * 31..24 reserved, 0
+ * 23..16 maximum input bytes
+ * 15.. 8 maximum output bytes
+ * 7.. 0 maximum bytes per UChar
+ *
+ * [18] Bit field containing numbers of UChars:
+ * 31..24 reserved, 0
+ * 23..16 maximum input UChars
+ * 15.. 8 maximum output UChars
+ * 7.. 0 maximum UChars per byte
+ *
+ * [19] Bit field containing flags:
+ * (extension table unicodeMask)
+ * 1 UCNV_HAS_SURROGATES flag for the extension table
+ * 0 UCNV_HAS_SUPPLEMENTARY flag for the extension table
+ *
+ * [20]..[30] reserved, 0
+ * [31] number of bytes for the entire extension structure
+ * [>31] reserved; there are indexes[0] indexes
+ *
+ *
+ * uint32_t toUTable[];
+ *
+ * Array of byte/value pairs for lookups for toUnicode conversion.
+ * The array is partitioned into sections like collation contraction tables.
+ * Each section contains one word with the number of following words and
+ * a default value for when the lookup in this section yields no match.
+ *
+ * A section is sorted in ascending order of input bytes,
+ * allowing for fast linear or binary searches.
+ * The builder may store entries for a contiguous range of byte values
+ * (compare difference between the first and last one with count),
+ * which then allows for direct array access.
+ * The builder should always do this for the initial table section.
+ *
+ * Entries may have 0 values, see below.
+ * No two entries in a section have the same byte values.
+ *
+ * Each uint32_t contains an input byte value in bits 31..24 and the
+ * corresponding lookup value in bits 23..0.
+ * Interpret the value as follows:
+ * if(value==0) {
+ * no match, see below
+ * } else if(value<0x1f0000) {
+ * partial match - use value as index to the next toUTable section
+ * and match the next unit; (value indexes toUTable[value])
+ * } else {
+ * if(bit 23 set) {
+ * roundtrip;
+ * } else {
+ * fallback;
+ * }
+ * unset value bit 23;
+ * if(value<=0x2fffff) {
+ * (value-0x1f0000) is a code point; (BMP: value<=0x1fffff)
+ * } else {
+ * bits 17..0 (value&0x3ffff) is an index to
+ * the result UChars in toUUChars[]; (0 indexes toUUChars[0])
+ * length of the result=((value>>18)-12); (length=0..19)
+ * }
+ * }
+ *
+ * The first word in a section contains the number of following words in the
+ * input byte position (bits 31..24, number=1..0xff).
+ * The value of the initial word is used when the current byte is not found
+ * in this section.
+ * If the value is not 0, then it represents a result as above.
+ * If the value is 0, then the search has to return a shorter match with an
+ * earlier default value as the result, or result in "unmappable" even for the
+ * initial bytes.
+ * If the value is 0 for the initial toUTable entry, then the initial byte
+ * does not start any mapping input.
+ *
+ *
+ * UChar toUUChars[];
+ *
+ * Contains toUnicode mapping results, stored as sequences of UChars.
+ * Indexes and lengths stored in the toUTable[].
+ *
+ *
+ * UChar fromUTableUChars[];
+ * uint32_t fromUTableValues[];
+ *
+ * The fromUTable is split into two arrays, but works otherwise much like
+ * the toUTable. The array is partitioned into sections like collation
+ * contraction tables and toUTable.
+ * A row in the table consists of same-index entries in fromUTableUChars[]
+ * and fromUTableValues[].
+ *
+ * Interpret a value as follows:
+ * if(value==0) {
+ * no match, see below
+ * } else if(value<=0xffffff) { (bits 31..24 are 0)
+ * partial match - use value as index to the next fromUTable section
+ * and match the next unit; (value indexes fromUTable[value])
+ * } else {
+ * if(value==0x80000001) {
+ * return no mapping, but request for ;
+ * }
+ * if(bit 31 set) {
+ * roundtrip;
+ * } else {
+ * fallback;
+ * }
+ * // bits 30..29 reserved, 0
+ * length=(value>>24)&0x1f; (bits 28..24)
+ * if(length==1..3) {
+ * bits 23..0 contain 1..3 bytes, padded with 00s on the left;
+ * } else {
+ * bits 23..0 (value&0xffffff) is an index to
+ * the result bytes in fromUBytes[]; (0 indexes fromUBytes[0])
+ * }
+ * }
+ *
+ * The first pair in a section contains the number of following pairs in the
+ * UChar position (16 bits, number=1..0xffff).
+ * The value of the initial pair is used when the current UChar is not found
+ * in this section.
+ * If the value is not 0, then it represents a result as above.
+ * If the value is 0, then the search has to return a shorter match with an
+ * earlier default value as the result, or result in "unmappable" even for the
+ * initial UChars.
+ *
+ * If the from Unicode trie is present, then the from Unicode search tables
+ * are not used for initial code points.
+ * In this case, the first entries (index 0) in the tables are not used
+ * (reserved, set to 0) because a value of 0 is used in trie results
+ * to indicate no mapping.
+ *
+ *
+ * uint16_t fromUStage12[];
+ *
+ * Stages 1 & 2 of a trie that maps an initial code point.
+ * Indexes in stage 1 are all offset by the length of stage 1 so that the
+ * same array pointer can be used for both stages.
+ * If (c>>10)>=(length of stage 1) then c does not start any mapping.
+ * Same bit distribution as for regular conversion tries.
+ *
+ *
+ * uint16_t fromUStage3[];
+ * uint32_t fromUStage3b[];
+ *
+ * Stage 3 of the trie. The first array simply contains indexes to the second,
+ * which contains words in the same format as fromUTableValues[].
+ * Use a stage 3 granularity of 4, which allows for 256k stage 3 entries,
+ * and 16-bit entries in stage 3 allow for 64k stage 3b entries.
+ * The stage 3 granularity means that the stage 2 entry needs to be left-shifted.
+ *
+ * Two arrays are used because it is expected that more than half of the stage 3
+ * entries will be zero. The 16-bit index stage 3 array saves space even
+ * considering storing a total of 6 bytes per non-zero entry in both arrays
+ * together.
+ * Using a stage 3 granularity of >1 diminishes the compactability in that stage
+ * but provides a larger effective addressing space in stage 2.
+ * All but the final result stage use 16-bit entries to save space.
+ *
+ * fromUStage3b[] contains a zero for "no mapping" at its index 0,
+ * and may contain UCNV_EXT_FROM_U_SUBCHAR1 at index 1 for " SUB mapping"
+ * (i.e., "no mapping" with preference for rather than ),
+ * and all other items are unique non-zero results.
+ *
+ * The default value of a fromUTableValues[] section that is referenced
+ * _directly_ from a fromUStage3b[] item may also be UCNV_EXT_FROM_U_SUBCHAR1,
+ * but this value must not occur anywhere else in fromUTableValues[]
+ * because "no mapping" is always a property of a single code point,
+ * never of multiple.
+ *
+ *
+ * char fromUBytes[];
+ *
+ * Contains fromUnicode mapping results, stored as sequences of chars.
+ * Indexes and lengths stored in the fromUTableValues[].
+ */
+enum {
+ UCNV_EXT_INDEXES_LENGTH, /* 0 */
+
+ UCNV_EXT_TO_U_INDEX, /* 1 */
+ UCNV_EXT_TO_U_LENGTH,
+ UCNV_EXT_TO_U_UCHARS_INDEX,
+ UCNV_EXT_TO_U_UCHARS_LENGTH,
+
+ UCNV_EXT_FROM_U_UCHARS_INDEX, /* 5 */
+ UCNV_EXT_FROM_U_VALUES_INDEX,
+ UCNV_EXT_FROM_U_LENGTH,
+ UCNV_EXT_FROM_U_BYTES_INDEX,
+ UCNV_EXT_FROM_U_BYTES_LENGTH,
+
+ UCNV_EXT_FROM_U_STAGE_12_INDEX, /* 10 */
+ UCNV_EXT_FROM_U_STAGE_1_LENGTH,
+ UCNV_EXT_FROM_U_STAGE_12_LENGTH,
+ UCNV_EXT_FROM_U_STAGE_3_INDEX,
+ UCNV_EXT_FROM_U_STAGE_3_LENGTH,
+ UCNV_EXT_FROM_U_STAGE_3B_INDEX,
+ UCNV_EXT_FROM_U_STAGE_3B_LENGTH,
+
+ UCNV_EXT_COUNT_BYTES, /* 17 */
+ UCNV_EXT_COUNT_UCHARS,
+ UCNV_EXT_FLAGS,
+
+ UCNV_EXT_RESERVED_INDEX, /* 20, moves with additional indexes */
+
+ UCNV_EXT_SIZE=31,
+ UCNV_EXT_INDEXES_MIN_LENGTH=32
+};
+
+/* get the pointer to an extension array from indexes[index] */
+#define UCNV_EXT_ARRAY(indexes, index, itemType) \
+ ((const itemType *)((const char *)(indexes)+(indexes)[index]))
+
+#define UCNV_GET_MAX_BYTES_PER_UCHAR(indexes) \
+ ((indexes)[UCNV_EXT_COUNT_BYTES]&0xff)
+
+/* internal API ------------------------------------------------------------- */
+
+U_CFUNC UBool
+ucnv_extInitialMatchToU(UConverter *cnv, const int32_t *cx,
+ int32_t firstLength,
+ const char **src, const char *srcLimit,
+ UChar **target, const UChar *targetLimit,
+ int32_t **offsets, int32_t srcIndex,
+ UBool flush,
+ UErrorCode *pErrorCode);
+
+U_CFUNC UChar32
+ucnv_extSimpleMatchToU(const int32_t *cx,
+ const char *source, int32_t length,
+ UBool useFallback);
+
+U_CFUNC void
+ucnv_extContinueMatchToU(UConverter *cnv,
+ UConverterToUnicodeArgs *pArgs, int32_t srcIndex,
+ UErrorCode *pErrorCode);
+
+
+U_CFUNC UBool
+ucnv_extInitialMatchFromU(UConverter *cnv, const int32_t *cx,
+ UChar32 cp,
+ const UChar **src, const UChar *srcLimit,
+ char **target, const char *targetLimit,
+ int32_t **offsets, int32_t srcIndex,
+ UBool flush,
+ UErrorCode *pErrorCode);
+
+U_CFUNC int32_t
+ucnv_extSimpleMatchFromU(const int32_t *cx,
+ UChar32 cp, uint32_t *pValue,
+ UBool useFallback);
+
+U_CFUNC void
+ucnv_extContinueMatchFromU(UConverter *cnv,
+ UConverterFromUnicodeArgs *pArgs, int32_t srcIndex,
+ UErrorCode *pErrorCode);
+
+U_CFUNC void
+ucnv_extGetUnicodeSet(const UConverterSharedData *sharedData,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode);
+
+/* toUnicode helpers -------------------------------------------------------- */
+
+#define UCNV_EXT_TO_U_BYTE_SHIFT 24
+#define UCNV_EXT_TO_U_VALUE_MASK 0xffffff
+#define UCNV_EXT_TO_U_MIN_CODE_POINT 0x1f0000
+#define UCNV_EXT_TO_U_MAX_CODE_POINT 0x2fffff
+#define UCNV_EXT_TO_U_ROUNDTRIP_FLAG ((uint32_t)1<<23)
+#define UCNV_EXT_TO_U_INDEX_MASK 0x3ffff
+#define UCNV_EXT_TO_U_LENGTH_SHIFT 18
+#define UCNV_EXT_TO_U_LENGTH_OFFSET 12
+
+/* maximum number of indexed UChars */
+#define UCNV_EXT_MAX_UCHARS 19
+
+#define UCNV_EXT_TO_U_MAKE_WORD(byte, value) (((uint32_t)(byte)<>UCNV_EXT_TO_U_BYTE_SHIFT)
+#define UCNV_EXT_TO_U_GET_VALUE(word) ((word)&UCNV_EXT_TO_U_VALUE_MASK)
+
+#define UCNV_EXT_TO_U_IS_PARTIAL(value) ((value)>UCNV_EXT_TO_U_LENGTH_SHIFT)-UCNV_EXT_TO_U_LENGTH_OFFSET)
+
+/* fromUnicode helpers ------------------------------------------------------ */
+
+/* most trie constants are shared with ucnvmbcs.h */
+
+/* see similar utrie.h UTRIE_INDEX_SHIFT and UTRIE_DATA_GRANULARITY */
+#define UCNV_EXT_STAGE_2_LEFT_SHIFT 2
+#define UCNV_EXT_STAGE_3_GRANULARITY 4
+
+/* trie access, returns the stage 3 value=index to stage 3b; s1Index=c>>10 */
+#define UCNV_EXT_FROM_U(stage12, stage3, s1Index, c) \
+ (stage3)[ ((int32_t)(stage12)[ (stage12)[s1Index] +(((c)>>4)&0x3f) ]< (impossible roundtrip to 0 bytes, value 01) */
+#define UCNV_EXT_FROM_U_SUBCHAR1 0x80000001
+
+/* at most 3 bytes in the lower part of the value */
+#define UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH 3
+
+/* maximum number of indexed bytes */
+#define UCNV_EXT_MAX_BYTES 0x1f
+
+#define UCNV_EXT_FROM_U_IS_PARTIAL(value) (((value)>>UCNV_EXT_FROM_U_LENGTH_SHIFT)==0)
+#define UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value) (value)
+
+#define UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) (((value)&UCNV_EXT_FROM_U_ROUNDTRIP_FLAG)!=0)
+#define UCNV_EXT_FROM_U_MASK_ROUNDTRIP(value) ((value)&~UCNV_EXT_FROM_U_ROUNDTRIP_FLAG)
+
+/* get length; masks away all other bits */
+#define UCNV_EXT_FROM_U_GET_LENGTH(value) (int32_t)(((value)>>UCNV_EXT_FROM_U_LENGTH_SHIFT)&UCNV_EXT_MAX_BYTES)
+
+/* get bytes or bytes index */
+#define UCNV_EXT_FROM_U_GET_DATA(value) ((value)&UCNV_EXT_FROM_U_DATA_MASK)
+
+#endif
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_imp.h b/Build/source/libs/icu/icu-xetex/common/ucnv_imp.h
new file mode 100644
index 00000000000..c1f48c0e186
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_imp.h
@@ -0,0 +1,95 @@
+/*
+**********************************************************************
+* Copyright (C) 1999-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+*
+* ucnv_imp.h:
+* Contains all internal and external data structure definitions
+* Created & Maitained by Bertrand A. Damiba
+*
+*
+*
+* ATTENTION:
+* ---------
+* Although the data structures in this file are open and stack allocatable
+* we reserve the right to hide them in further releases.
+*/
+
+#ifndef UCNV_IMP_H
+#define UCNV_IMP_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/uloc.h"
+#include "ucnv_bld.h"
+
+/* figures out if we need to go to file to read in the data tables.
+ * @param converterName The name of the converter
+ * @param err The error code
+ * @return the newly created converter
+ */
+UConverter *ucnv_createConverter (UConverter *myUConverter, const char *converterName, UErrorCode * err);
+
+/*
+ * Open a purely algorithmic converter, specified by a type constant.
+ * @param myUConverter NULL, or pre-allocated UConverter structure to avoid
+ * a memory allocation
+ * @param type requested converter type
+ * @param locale locale parameter, or ""
+ * @param options converter options bit set (default 0)
+ * @param err ICU error code, not tested for U_FAILURE on input
+ * because this is an internal function
+ * @internal
+ */
+U_CFUNC UConverter *
+ucnv_createAlgorithmicConverter(UConverter *myUConverter,
+ UConverterType type,
+ const char *locale, uint32_t options,
+ UErrorCode *err);
+
+/* Creates a converter from shared data
+ */
+UConverter*
+ucnv_createConverterFromSharedData(UConverter *myUConverter, UConverterSharedData *mySharedConverterData, const char *realName, const char *locale, uint32_t options, UErrorCode *err);
+
+UConverter* ucnv_createConverterFromPackage(const char *packageName, const char *converterName,
+ UErrorCode *err);
+
+typedef struct {
+ char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH], locale[ULOC_FULLNAME_CAPACITY];
+ const char *realName;
+ uint32_t options;
+} UConverterLookupData;
+
+/**
+ * Load a converter but do not create a UConverter object.
+ * Simply return the UConverterSharedData.
+ * Performs alias lookup etc.
+ * @internal
+ */
+UConverterSharedData *
+ucnv_loadSharedData(const char *converterName, UConverterLookupData *lookup, UErrorCode * err);
+
+/**
+ * This may unload the shared data in a thread safe manner.
+ * This will only unload the data if no other converters are sharing it.
+ */
+void
+ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData);
+
+/**
+ * This is a thread safe way to increment the reference count.
+ */
+void
+ucnv_incrementRefCount(UConverterSharedData *sharedData);
+
+#define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE)
+#define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE)
+
+#endif
+
+#endif /* _UCNV_IMP */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_io.c b/Build/source/libs/icu/icu-xetex/common/ucnv_io.c
new file mode 100644
index 00000000000..29876a6714f
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_io.c
@@ -0,0 +1,1341 @@
+/*
+******************************************************************************
+*
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+*
+*
+* ucnv_io.c:
+* initializes global variables and defines functions pertaining to converter
+* name resolution aspect of the conversion code.
+*
+* new implementation:
+*
+* created on: 1999nov22
+* created by: Markus W. Scherer
+*
+* Use the binary cnvalias.icu (created from convrtrs.txt) to work
+* with aliases for converter names.
+*
+* Date Name Description
+* 11/22/1999 markus Created
+* 06/28/2002 grhoten Major overhaul of the converter alias design.
+* Now an alias can map to different converters
+* depending on the specified standard.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "unicode/udata.h"
+
+#include "umutex.h"
+#include "uarrsort.h"
+#include "udataswp.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "ucnv_io.h"
+#include "uenumimp.h"
+#include "ucln_cmn.h"
+
+/* Format of cnvalias.icu -----------------------------------------------------
+ *
+ * cnvalias.icu is a binary, memory-mappable form of convrtrs.txt.
+ * This binary form contains several tables. All indexes are to uint16_t
+ * units, and not to the bytes (uint8_t units). Addressing everything on
+ * 16-bit boundaries allows us to store more information with small index
+ * numbers, which are also 16-bit in size. The majority of the table (except
+ * the string table) are 16-bit numbers.
+ *
+ * First there is the size of the Table of Contents (TOC). The TOC
+ * entries contain the size of each section. In order to find the offset
+ * you just need to sum up the previous offsets.
+ * The TOC length and entries are an array of uint32_t values.
+ * The first section after the TOC starts immediately after the TOC.
+ *
+ * 1) This section contains a list of converters. This list contains indexes
+ * into the string table for the converter name. The index of this list is
+ * also used by other sections, which are mentioned later on.
+ * This list is not sorted.
+ *
+ * 2) This section contains a list of tags. This list contains indexes
+ * into the string table for the tag name. The index of this list is
+ * also used by other sections, which are mentioned later on.
+ * This list is in priority order of standards.
+ *
+ * 3) This section contains a list of sorted unique aliases. This
+ * list contains indexes into the string table for the alias name. The
+ * index of this list is also used by other sections, like the 4th section.
+ * The index for the 3rd and 4th section is used to get the
+ * alias -> converter name mapping. Section 3 and 4 form a two column table.
+ * Some of the most significant bits of each index may contain other
+ * information (see findConverter for details).
+ *
+ * 4) This section contains a list of mapped converter names. Consider this
+ * as a table that maps the 3rd section to the 1st section. This list contains
+ * indexes into the 1st section. The index of this list is the same index in
+ * the 3rd section. There is also some extra information in the high bits of
+ * each converter index in this table. Currently it's only used to say that
+ * an alias mapped to this converter is ambiguous. See UCNV_CONVERTER_INDEX_MASK
+ * and UCNV_AMBIGUOUS_ALIAS_MAP_BIT for more information. This section is
+ * the predigested form of the 5th section so that an alias lookup can be fast.
+ *
+ * 5) This section contains a 2D array with indexes to the 6th section. This
+ * section is the full form of all alias mappings. The column index is the
+ * index into the converter list (column header). The row index is the index
+ * to tag list (row header). This 2D array is the top part a 3D array. The
+ * third dimension is in the 6th section.
+ *
+ * 6) This is blob of variable length arrays. Each array starts with a size,
+ * and is followed by indexes to alias names in the string table. This is
+ * the third dimension to the section 5. No other section should be referencing
+ * this section.
+ *
+ * 7) Starting in ICU 3.6, this can be a UConverterAliasOptions struct. Its
+ * presence indicates that a section 9 exists. UConverterAliasOptions specifies
+ * what type of string normalization is used among other potential things in the
+ * future.
+ *
+ * 8) This is the string table. All strings are indexed on an even address.
+ * There are two reasons for this. First many chip architectures locate strings
+ * faster on even address boundaries. Second, since all indexes are 16-bit
+ * numbers, this string table can be 128KB in size instead of 64KB when we
+ * only have strings starting on an even address.
+ *
+ * 9) When present this is a set of prenormalized strings from section 8. This
+ * table contains normalized strings with the dashes and spaces stripped out,
+ * and all strings lowercased. In the future, the options in section 7 may state
+ * other types of normalization.
+ *
+ * Here is the concept of section 5 and 6. It's a 3D cube. Each tag
+ * has a unique alias among all converters. That same alias can
+ * be mentioned in other standards on different converters,
+ * but only one alias per tag can be unique.
+ *
+ *
+ * Converter Names (Usually in TR22 form)
+ * -------------------------------------------.
+ * T / /|
+ * a / / |
+ * g / / |
+ * s / / |
+ * / / |
+ * ------------------------------------------/ |
+ * A | | |
+ * l | | |
+ * i | | /
+ * a | | /
+ * s | | /
+ * e | | /
+ * s | |/
+ * -------------------------------------------
+ *
+ *
+ *
+ * Here is what it really looks like. It's like swiss cheese.
+ * There are holes. Some converters aren't recognized by
+ * a standard, or they are really old converters that the
+ * standard doesn't recognize anymore.
+ *
+ * Converter Names (Usually in TR22 form)
+ * -------------------------------------------.
+ * T /##########################################/|
+ * a / # # /#
+ * g / # ## ## ### # ### ### ### #/
+ * s / # ##### #### ## ## #/#
+ * / ### # # ## # # # ### # # #/##
+ * ------------------------------------------/# #
+ * A |### # # ## # # # ### # # #|# #
+ * l |# # # # # ## # #|# #
+ * i |# # # # # # #|#
+ * a |# #|#
+ * s | #|#
+ * e
+ * s
+ *
+ */
+
+/**
+ * Used by the UEnumeration API
+ */
+typedef struct UAliasContext {
+ uint32_t listOffset;
+ uint32_t listIdx;
+} UAliasContext;
+
+static const char DATA_NAME[] = "cnvalias";
+static const char DATA_TYPE[] = "icu";
+
+static UDataMemory *gAliasData=NULL;
+
+enum {
+ tocLengthIndex=0,
+ converterListIndex=1,
+ tagListIndex=2,
+ aliasListIndex=3,
+ untaggedConvArrayIndex=4,
+ taggedAliasArrayIndex=5,
+ taggedAliasListsIndex=6,
+ tableOptionsIndex=7,
+ stringTableIndex=8,
+ normalizedStringTableIndex=9,
+ offsetsCount, /* length of the swapper's temporary offsets[] */
+ minTocLength=8 /* min. tocLength in the file, does not count the tocLengthIndex! */
+};
+
+static const UConverterAliasOptions defaultTableOptions = {
+ UCNV_IO_UNNORMALIZED,
+ 0 /* containsCnvOptionInfo */
+};
+static UConverterAlias gMainTable;
+
+#define GET_STRING(idx) (const char *)(gMainTable.stringTable + (idx))
+#define GET_NORMALIZED_STRING(idx) (const char *)(gMainTable.normalizedStringTable + (idx))
+
+static UBool U_CALLCONV
+isAcceptable(void *context,
+ const char *type, const char *name,
+ const UDataInfo *pInfo) {
+ return (UBool)(
+ pInfo->size>=20 &&
+ pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
+ pInfo->charsetFamily==U_CHARSET_FAMILY &&
+ pInfo->dataFormat[0]==0x43 && /* dataFormat="CvAl" */
+ pInfo->dataFormat[1]==0x76 &&
+ pInfo->dataFormat[2]==0x41 &&
+ pInfo->dataFormat[3]==0x6c &&
+ pInfo->formatVersion[0]==3);
+}
+
+static UBool U_CALLCONV ucnv_io_cleanup(void)
+{
+ if (gAliasData) {
+ udata_close(gAliasData);
+ gAliasData = NULL;
+ }
+
+ uprv_memset(&gMainTable, 0, sizeof(gMainTable));
+
+ return TRUE; /* Everything was cleaned up */
+}
+
+static UBool
+haveAliasData(UErrorCode *pErrorCode) {
+ int needInit;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return FALSE;
+ }
+
+ UMTX_CHECK(NULL, (gAliasData==NULL), needInit);
+
+ /* load converter alias data from file if necessary */
+ if (needInit) {
+ UDataMemory *data;
+ const uint16_t *table;
+ const uint32_t *sectionSizes;
+ uint32_t tableStart;
+ uint32_t currOffset;
+
+ data = udata_openChoice(NULL, DATA_TYPE, DATA_NAME, isAcceptable, NULL, pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ return FALSE;
+ }
+
+ sectionSizes = (const uint32_t *)udata_getMemory(data);
+ table = (const uint16_t *)sectionSizes;
+
+ tableStart = sectionSizes[0];
+ if (tableStart < minTocLength) {
+ *pErrorCode = U_INVALID_FORMAT_ERROR;
+ udata_close(data);
+ return FALSE;
+ }
+
+ umtx_lock(NULL);
+ if(gAliasData==NULL) {
+ gAliasData = data;
+ data=NULL;
+
+ gMainTable.converterListSize = sectionSizes[1];
+ gMainTable.tagListSize = sectionSizes[2];
+ gMainTable.aliasListSize = sectionSizes[3];
+ gMainTable.untaggedConvArraySize = sectionSizes[4];
+ gMainTable.taggedAliasArraySize = sectionSizes[5];
+ gMainTable.taggedAliasListsSize = sectionSizes[6];
+ gMainTable.optionTableSize = sectionSizes[7];
+ gMainTable.stringTableSize = sectionSizes[8];
+
+ if (tableStart > 8) {
+ gMainTable.normalizedStringTableSize = sectionSizes[9];
+ }
+
+ currOffset = tableStart * (sizeof(uint32_t)/sizeof(uint16_t)) + (sizeof(uint32_t)/sizeof(uint16_t));
+ gMainTable.converterList = table + currOffset;
+
+ currOffset += gMainTable.converterListSize;
+ gMainTable.tagList = table + currOffset;
+
+ currOffset += gMainTable.tagListSize;
+ gMainTable.aliasList = table + currOffset;
+
+ currOffset += gMainTable.aliasListSize;
+ gMainTable.untaggedConvArray = table + currOffset;
+
+ currOffset += gMainTable.untaggedConvArraySize;
+ gMainTable.taggedAliasArray = table + currOffset;
+
+ /* aliasLists is a 1's based array, but it has a padding character */
+ currOffset += gMainTable.taggedAliasArraySize;
+ gMainTable.taggedAliasLists = table + currOffset;
+
+ currOffset += gMainTable.taggedAliasListsSize;
+ if (gMainTable.optionTableSize > 0
+ && ((const UConverterAliasOptions *)(table + currOffset))->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
+ {
+ /* Faster table */
+ gMainTable.optionTable = (const UConverterAliasOptions *)(table + currOffset);
+ }
+ else {
+ /* Smaller table, or I can't handle this normalization mode!
+ Use the original slower table lookup. */
+ gMainTable.optionTable = &defaultTableOptions;
+ }
+
+ currOffset += gMainTable.optionTableSize;
+ gMainTable.stringTable = table + currOffset;
+
+ currOffset += gMainTable.stringTableSize;
+ gMainTable.normalizedStringTable = ((gMainTable.optionTable->stringNormalizationType == UCNV_IO_UNNORMALIZED)
+ ? gMainTable.stringTable : (table + currOffset));
+
+ ucln_common_registerCleanup(UCLN_COMMON_UCNV_IO, ucnv_io_cleanup);
+ }
+ umtx_unlock(NULL);
+
+ /* if a different thread set it first, then close the extra data */
+ if(data!=NULL) {
+ udata_close(data); /* NULL if it was set correctly */
+ }
+ }
+
+ return TRUE;
+}
+
+static U_INLINE UBool
+isAlias(const char *alias, UErrorCode *pErrorCode) {
+ if(alias==NULL) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+ return (UBool)(*alias!=0);
+}
+
+static uint32_t getTagNumber(const char *tagname) {
+ if (gMainTable.tagList) {
+ uint32_t tagNum;
+ for (tagNum = 0; tagNum < gMainTable.tagListSize; tagNum++) {
+ if (!uprv_stricmp(GET_STRING(gMainTable.tagList[tagNum]), tagname)) {
+ return tagNum;
+ }
+ }
+ }
+
+ return UINT32_MAX;
+}
+
+/* character types relevant for ucnv_compareNames() */
+enum {
+ IGNORE,
+ ZERO,
+ NONZERO,
+ MINLETTER /* any values from here on are lowercase letter mappings */
+};
+
+/* character types for ASCII 00..7F */
+static const uint8_t asciiTypes[128] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ ZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, 0, 0, 0, 0, 0, 0,
+ 0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0, 0, 0, 0, 0,
+ 0, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0, 0, 0, 0, 0
+};
+
+#define GET_ASCII_TYPE(c) ((int8_t)(c) >= 0 ? asciiTypes[(uint8_t)c] : (uint8_t)IGNORE)
+
+/* character types for EBCDIC 80..FF */
+static const uint8_t ebcdicTypes[128] = {
+ 0, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0, 0, 0, 0, 0, 0,
+ 0, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0, 0, 0, 0, 0, 0,
+ 0, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0, 0, 0, 0, 0, 0,
+ ZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, 0, 0, 0, 0, 0, 0
+};
+
+#define GET_EBCDIC_TYPE(c) ((int8_t)(c) < 0 ? ebcdicTypes[(c)&0x7f] : (uint8_t)IGNORE)
+
+#if U_CHARSET_FAMILY==U_ASCII_FAMILY
+# define GET_CHAR_TYPE(c) GET_ASCII_TYPE(c)
+#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+# define GET_CHAR_TYPE(c) GET_EBCDIC_TYPE(c)
+#else
+# error U_CHARSET_FAMILY is not valid
+#endif
+
+/* @see ucnv_compareNames */
+U_CFUNC char * U_EXPORT2
+ucnv_io_stripASCIIForCompare(char *dst, const char *name) {
+ char *dstItr = dst;
+ uint8_t type, nextType;
+ char c1;
+ UBool afterDigit = FALSE;
+
+ while ((c1 = *name++) != 0) {
+ type = GET_ASCII_TYPE(c1);
+ switch (type) {
+ case IGNORE:
+ afterDigit = FALSE;
+ continue; /* ignore all but letters and digits */
+ case ZERO:
+ if (!afterDigit) {
+ nextType = GET_ASCII_TYPE(*name);
+ if (nextType == ZERO || nextType == NONZERO) {
+ continue; /* ignore leading zero before another digit */
+ }
+ }
+ break;
+ case NONZERO:
+ afterDigit = TRUE;
+ break;
+ default:
+ c1 = (char)type; /* lowercased letter */
+ afterDigit = FALSE;
+ break;
+ }
+ *dstItr++ = c1;
+ }
+ *dstItr = 0;
+ return dst;
+}
+
+U_CFUNC char * U_EXPORT2
+ucnv_io_stripEBCDICForCompare(char *dst, const char *name) {
+ char *dstItr = dst;
+ uint8_t type, nextType;
+ char c1;
+ UBool afterDigit = FALSE;
+
+ while ((c1 = *name++) != 0) {
+ type = GET_EBCDIC_TYPE(c1);
+ switch (type) {
+ case IGNORE:
+ afterDigit = FALSE;
+ continue; /* ignore all but letters and digits */
+ case ZERO:
+ if (!afterDigit) {
+ nextType = GET_EBCDIC_TYPE(*name);
+ if (nextType == ZERO || nextType == NONZERO) {
+ continue; /* ignore leading zero before another digit */
+ }
+ }
+ break;
+ case NONZERO:
+ afterDigit = TRUE;
+ break;
+ default:
+ c1 = (char)type; /* lowercased letter */
+ afterDigit = FALSE;
+ break;
+ }
+ *dstItr++ = c1;
+ }
+ *dstItr = 0;
+ return dst;
+}
+
+/**
+ * Do a fuzzy compare of two converter/alias names.
+ * The comparison is case-insensitive, ignores leading zeroes if they are not
+ * followed by further digits, and ignores all but letters and digits.
+ * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
+ * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
+ * at http://www.unicode.org/reports/tr22/
+ *
+ * This is a symmetrical (commutative) operation; order of arguments
+ * is insignificant. This is an important property for sorting the
+ * list (when the list is preprocessed into binary form) and for
+ * performing binary searches on it at run time.
+ *
+ * @param name1 a converter name or alias, zero-terminated
+ * @param name2 a converter name or alias, zero-terminated
+ * @return 0 if the names match, or a negative value if the name1
+ * lexically precedes name2, or a positive value if the name1
+ * lexically follows name2.
+ *
+ * @see ucnv_io_stripForCompare
+ */
+U_CAPI int U_EXPORT2
+ucnv_compareNames(const char *name1, const char *name2) {
+ int rc;
+ uint8_t type, nextType;
+ char c1, c2;
+ UBool afterDigit1 = FALSE, afterDigit2 = FALSE;
+
+ for (;;) {
+ while ((c1 = *name1++) != 0) {
+ type = GET_CHAR_TYPE(c1);
+ switch (type) {
+ case IGNORE:
+ afterDigit1 = FALSE;
+ continue; /* ignore all but letters and digits */
+ case ZERO:
+ if (!afterDigit1) {
+ nextType = GET_CHAR_TYPE(*name1);
+ if (nextType == ZERO || nextType == NONZERO) {
+ continue; /* ignore leading zero before another digit */
+ }
+ }
+ break;
+ case NONZERO:
+ afterDigit1 = TRUE;
+ break;
+ default:
+ c1 = (char)type; /* lowercased letter */
+ afterDigit1 = FALSE;
+ break;
+ }
+ break; /* deliver c1 */
+ }
+ while ((c2 = *name2++) != 0) {
+ type = GET_CHAR_TYPE(c2);
+ switch (type) {
+ case IGNORE:
+ afterDigit2 = FALSE;
+ continue; /* ignore all but letters and digits */
+ case ZERO:
+ if (!afterDigit2) {
+ nextType = GET_CHAR_TYPE(*name2);
+ if (nextType == ZERO || nextType == NONZERO) {
+ continue; /* ignore leading zero before another digit */
+ }
+ }
+ break;
+ case NONZERO:
+ afterDigit2 = TRUE;
+ break;
+ default:
+ c2 = (char)type; /* lowercased letter */
+ afterDigit2 = FALSE;
+ break;
+ }
+ break; /* deliver c2 */
+ }
+
+ /* If we reach the ends of both strings then they match */
+ if ((c1|c2)==0) {
+ return 0;
+ }
+
+ /* Case-insensitive comparison */
+ rc = (int)(unsigned char)c1 - (int)(unsigned char)c2;
+ if (rc != 0) {
+ return rc;
+ }
+ }
+}
+
+/*
+ * search for an alias
+ * return the converter number index for gConverterList
+ */
+static U_INLINE uint32_t
+findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) {
+ uint32_t mid, start, limit;
+ uint32_t lastMid;
+ int result;
+ int isUnnormalized = (gMainTable.optionTable->stringNormalizationType == UCNV_IO_UNNORMALIZED);
+ char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH];
+
+ if (!isUnnormalized) {
+ if (uprv_strlen(alias) >= UCNV_MAX_CONVERTER_NAME_LENGTH) {
+ *pErrorCode = U_BUFFER_OVERFLOW_ERROR;
+ return UINT32_MAX;
+ }
+
+ /* Lower case and remove ignoreable characters. */
+ ucnv_io_stripForCompare(strippedName, alias);
+ alias = strippedName;
+ }
+
+ /* do a binary search for the alias */
+ start = 0;
+ limit = gMainTable.untaggedConvArraySize;
+ mid = limit;
+ lastMid = UINT32_MAX;
+
+ for (;;) {
+ mid = (uint32_t)((start + limit) / 2);
+ if (lastMid == mid) { /* Have we moved? */
+ break; /* We haven't moved, and it wasn't found. */
+ }
+ lastMid = mid;
+ if (isUnnormalized) {
+ result = ucnv_compareNames(alias, GET_STRING(gMainTable.aliasList[mid]));
+ }
+ else {
+ result = uprv_strcmp(alias, GET_NORMALIZED_STRING(gMainTable.aliasList[mid]));
+ }
+
+ if (result < 0) {
+ limit = mid;
+ } else if (result > 0) {
+ start = mid;
+ } else {
+ /* Since the gencnval tool folds duplicates into one entry,
+ * this alias in gAliasList is unique, but different standards
+ * may map an alias to different converters.
+ */
+ if (gMainTable.untaggedConvArray[mid] & UCNV_AMBIGUOUS_ALIAS_MAP_BIT) {
+ *pErrorCode = U_AMBIGUOUS_ALIAS_WARNING;
+ }
+ /* State whether the canonical converter name contains an option.
+ This information is contained in this list in order to maintain backward & forward compatibility. */
+ if (containsOption) {
+ UBool containsCnvOptionInfo = (UBool)gMainTable.optionTable->containsCnvOptionInfo;
+ *containsOption = (UBool)((containsCnvOptionInfo
+ && ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0))
+ || !containsCnvOptionInfo);
+ }
+ return gMainTable.untaggedConvArray[mid] & UCNV_CONVERTER_INDEX_MASK;
+ }
+ }
+
+ return UINT32_MAX;
+}
+
+/*
+ * Is this alias in this list?
+ * alias and listOffset should be non-NULL.
+ */
+static U_INLINE UBool
+isAliasInList(const char *alias, uint32_t listOffset) {
+ if (listOffset) {
+ uint32_t currAlias;
+ uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
+ /* +1 to skip listCount */
+ const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
+ for (currAlias = 0; currAlias < listCount; currAlias++) {
+ if (currList[currAlias]
+ && ucnv_compareNames(alias, GET_STRING(currList[currAlias]))==0)
+ {
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+/*
+ * Search for an standard name of an alias (what is the default name
+ * that this standard uses?)
+ * return the listOffset for gTaggedAliasLists. If it's 0,
+ * the it couldn't be found, but the parameters are valid.
+ */
+static uint32_t
+findTaggedAliasListsOffset(const char *alias, const char *standard, UErrorCode *pErrorCode) {
+ uint32_t idx;
+ uint32_t listOffset;
+ uint32_t convNum;
+ UErrorCode myErr = U_ZERO_ERROR;
+ uint32_t tagNum = getTagNumber(standard);
+
+ /* Make a quick guess. Hopefully they used a TR22 canonical alias. */
+ convNum = findConverter(alias, NULL, &myErr);
+ if (myErr != U_ZERO_ERROR) {
+ *pErrorCode = myErr;
+ }
+
+ if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
+ listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum];
+ if (listOffset && gMainTable.taggedAliasLists[listOffset + 1]) {
+ return listOffset;
+ }
+ if (myErr == U_AMBIGUOUS_ALIAS_WARNING) {
+ /* Uh Oh! They used an ambiguous alias.
+ We have to search the whole swiss cheese starting
+ at the highest standard affinity.
+ This may take a while.
+ */
+ for (idx = 0; idx < gMainTable.taggedAliasArraySize; idx++) {
+ listOffset = gMainTable.taggedAliasArray[idx];
+ if (listOffset && isAliasInList(alias, listOffset)) {
+ uint32_t currTagNum = idx/gMainTable.converterListSize;
+ uint32_t currConvNum = (idx - currTagNum*gMainTable.converterListSize);
+ uint32_t tempListOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + currConvNum];
+ if (tempListOffset && gMainTable.taggedAliasLists[tempListOffset + 1]) {
+ return tempListOffset;
+ }
+ /* else keep on looking */
+ /* We could speed this up by starting on the next row
+ because an alias is unique per row, right now.
+ This would change if alias versioning appears. */
+ }
+ }
+ /* The standard doesn't know about the alias */
+ }
+ /* else no default name */
+ return 0;
+ }
+ /* else converter or tag not found */
+
+ return UINT32_MAX;
+}
+
+/* Return the canonical name */
+static uint32_t
+findTaggedConverterNum(const char *alias, const char *standard, UErrorCode *pErrorCode) {
+ uint32_t idx;
+ uint32_t listOffset;
+ uint32_t convNum;
+ UErrorCode myErr = U_ZERO_ERROR;
+ uint32_t tagNum = getTagNumber(standard);
+
+ /* Make a quick guess. Hopefully they used a TR22 canonical alias. */
+ convNum = findConverter(alias, NULL, &myErr);
+ if (myErr != U_ZERO_ERROR) {
+ *pErrorCode = myErr;
+ }
+
+ if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
+ listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum];
+ if (listOffset && isAliasInList(alias, listOffset)) {
+ return convNum;
+ }
+ if (myErr == U_AMBIGUOUS_ALIAS_WARNING) {
+ /* Uh Oh! They used an ambiguous alias.
+ We have to search one slice of the swiss cheese.
+ We search only in the requested tag, not the whole thing.
+ This may take a while.
+ */
+ uint32_t convStart = (tagNum)*gMainTable.converterListSize;
+ uint32_t convLimit = (tagNum+1)*gMainTable.converterListSize;
+ for (idx = convStart; idx < convLimit; idx++) {
+ listOffset = gMainTable.taggedAliasArray[idx];
+ if (listOffset && isAliasInList(alias, listOffset)) {
+ return idx-convStart;
+ }
+ }
+ /* The standard doesn't know about the alias */
+ }
+ /* else no canonical name */
+ }
+ /* else converter or tag not found */
+
+ return UINT32_MAX;
+}
+
+
+
+U_CFUNC const char *
+ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) {
+ if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t convNum = findConverter(alias, containsOption, pErrorCode);
+ if (convNum < gMainTable.converterListSize) {
+ return GET_STRING(gMainTable.converterList[convNum]);
+ }
+ /* else converter not found */
+ }
+ return NULL;
+}
+
+static int32_t U_CALLCONV
+ucnv_io_countStandardAliases(UEnumeration *enumerator, UErrorCode *pErrorCode) {
+ int32_t value = 0;
+ UAliasContext *myContext = (UAliasContext *)(enumerator->context);
+ uint32_t listOffset = myContext->listOffset;
+
+ if (listOffset) {
+ value = gMainTable.taggedAliasLists[listOffset];
+ }
+ return value;
+}
+
+static const char* U_CALLCONV
+ucnv_io_nextStandardAliases(UEnumeration *enumerator,
+ int32_t* resultLength,
+ UErrorCode *pErrorCode)
+{
+ UAliasContext *myContext = (UAliasContext *)(enumerator->context);
+ uint32_t listOffset = myContext->listOffset;
+
+ if (listOffset) {
+ uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
+ const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
+
+ if (myContext->listIdx < listCount) {
+ const char *myStr = GET_STRING(currList[myContext->listIdx++]);
+ if (resultLength) {
+ *resultLength = (int32_t)uprv_strlen(myStr);
+ }
+ return myStr;
+ }
+ }
+ /* Either we accessed a zero length list, or we enumerated too far. */
+ if (resultLength) {
+ *resultLength = 0;
+ }
+ return NULL;
+}
+
+static void U_CALLCONV
+ucnv_io_resetStandardAliases(UEnumeration *enumerator, UErrorCode *pErrorCode) {
+ ((UAliasContext *)(enumerator->context))->listIdx = 0;
+}
+
+static void U_CALLCONV
+ucnv_io_closeUEnumeration(UEnumeration *enumerator) {
+ uprv_free(enumerator->context);
+ uprv_free(enumerator);
+}
+
+/* Enumerate the aliases for the specified converter and standard tag */
+static const UEnumeration gEnumAliases = {
+ NULL,
+ NULL,
+ ucnv_io_closeUEnumeration,
+ ucnv_io_countStandardAliases,
+ uenum_unextDefault,
+ ucnv_io_nextStandardAliases,
+ ucnv_io_resetStandardAliases
+};
+
+U_CAPI UEnumeration * U_EXPORT2
+ucnv_openStandardNames(const char *convName,
+ const char *standard,
+ UErrorCode *pErrorCode)
+{
+ UEnumeration *myEnum = NULL;
+ if (haveAliasData(pErrorCode) && isAlias(convName, pErrorCode)) {
+ uint32_t listOffset = findTaggedAliasListsOffset(convName, standard, pErrorCode);
+
+ /* When listOffset == 0, we want to acknowledge that the
+ converter name and standard are okay, but there
+ is nothing to enumerate. */
+ if (listOffset < gMainTable.taggedAliasListsSize) {
+ UAliasContext *myContext;
+
+ myEnum = uprv_malloc(sizeof(UEnumeration));
+ if (myEnum == NULL) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memcpy(myEnum, &gEnumAliases, sizeof(UEnumeration));
+ myContext = uprv_malloc(sizeof(UAliasContext));
+ if (myContext == NULL) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ uprv_free(myEnum);
+ return NULL;
+ }
+ myContext->listOffset = listOffset;
+ myContext->listIdx = 0;
+ myEnum->context = myContext;
+ }
+ /* else converter or tag not found */
+ }
+ return myEnum;
+}
+
+static uint16_t
+ucnv_io_countAliases(const char *alias, UErrorCode *pErrorCode) {
+ if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t convNum = findConverter(alias, NULL, pErrorCode);
+ if (convNum < gMainTable.converterListSize) {
+ /* tagListNum - 1 is the ALL tag */
+ int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
+
+ if (listOffset) {
+ return gMainTable.taggedAliasLists[listOffset];
+ }
+ /* else this shouldn't happen. internal program error */
+ }
+ /* else converter not found */
+ }
+ return 0;
+}
+
+static uint16_t
+ucnv_io_getAliases(const char *alias, uint16_t start, const char **aliases, UErrorCode *pErrorCode) {
+ if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t currAlias;
+ uint32_t convNum = findConverter(alias, NULL, pErrorCode);
+ if (convNum < gMainTable.converterListSize) {
+ /* tagListNum - 1 is the ALL tag */
+ int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
+
+ if (listOffset) {
+ uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
+ /* +1 to skip listCount */
+ const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
+
+ for (currAlias = start; currAlias < listCount; currAlias++) {
+ aliases[currAlias] = GET_STRING(currList[currAlias]);
+ }
+ }
+ /* else this shouldn't happen. internal program error */
+ }
+ /* else converter not found */
+ }
+ return 0;
+}
+
+static const char *
+ucnv_io_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode) {
+ if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t convNum = findConverter(alias, NULL, pErrorCode);
+ if (convNum < gMainTable.converterListSize) {
+ /* tagListNum - 1 is the ALL tag */
+ int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
+
+ if (listOffset) {
+ uint32_t listCount = gMainTable.taggedAliasLists[listOffset];
+ /* +1 to skip listCount */
+ const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
+
+ if (n < listCount) {
+ return GET_STRING(currList[n]);
+ }
+ *pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ /* else this shouldn't happen. internal program error */
+ }
+ /* else converter not found */
+ }
+ return NULL;
+}
+
+static uint16_t
+ucnv_io_countStandards(UErrorCode *pErrorCode) {
+ if (haveAliasData(pErrorCode)) {
+ /* Don't include the empty list */
+ return (uint16_t)(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
+ }
+
+ return 0;
+}
+
+U_CAPI const char * U_EXPORT2
+ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode) {
+ if (haveAliasData(pErrorCode)) {
+ if (n < gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) {
+ return GET_STRING(gMainTable.tagList[n]);
+ }
+ *pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+
+ return NULL;
+}
+
+U_CAPI const char * U_EXPORT2
+ucnv_getStandardName(const char *alias, const char *standard, UErrorCode *pErrorCode) {
+ if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t listOffset = findTaggedAliasListsOffset(alias, standard, pErrorCode);
+
+ if (0 < listOffset && listOffset < gMainTable.taggedAliasListsSize) {
+ const uint16_t *currList = gMainTable.taggedAliasLists + listOffset + 1;
+
+ /* Get the preferred name from this list */
+ if (currList[0]) {
+ return GET_STRING(currList[0]);
+ }
+ /* else someone screwed up the alias table. */
+ /* *pErrorCode = U_INVALID_FORMAT_ERROR */
+ }
+ }
+
+ return NULL;
+}
+
+U_CAPI uint16_t U_EXPORT2
+ucnv_countAliases(const char *alias, UErrorCode *pErrorCode)
+{
+ return ucnv_io_countAliases(alias, pErrorCode);
+}
+
+
+U_CAPI const char* U_EXPORT2
+ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode)
+{
+ return ucnv_io_getAlias(alias, n, pErrorCode);
+}
+
+U_CAPI void U_EXPORT2
+ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode)
+{
+ ucnv_io_getAliases(alias, 0, aliases, pErrorCode);
+}
+
+U_CAPI uint16_t U_EXPORT2
+ucnv_countStandards(void)
+{
+ UErrorCode err = U_ZERO_ERROR;
+ return ucnv_io_countStandards(&err);
+}
+
+U_CAPI const char * U_EXPORT2
+ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode) {
+ if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
+ uint32_t convNum = findTaggedConverterNum(alias, standard, pErrorCode);
+
+ if (convNum < gMainTable.converterListSize) {
+ return GET_STRING(gMainTable.converterList[convNum]);
+ }
+ }
+
+ return NULL;
+}
+
+static int32_t U_CALLCONV
+ucnv_io_countAllConverters(UEnumeration *enumerator, UErrorCode *pErrorCode) {
+ return gMainTable.converterListSize;
+}
+
+static const char* U_CALLCONV
+ucnv_io_nextAllConverters(UEnumeration *enumerator,
+ int32_t* resultLength,
+ UErrorCode *pErrorCode)
+{
+ uint16_t *myContext = (uint16_t *)(enumerator->context);
+
+ if (*myContext < gMainTable.converterListSize) {
+ const char *myStr = GET_STRING(gMainTable.converterList[(*myContext)++]);
+ if (resultLength) {
+ *resultLength = (int32_t)uprv_strlen(myStr);
+ }
+ return myStr;
+ }
+ /* Either we accessed a zero length list, or we enumerated too far. */
+ if (resultLength) {
+ *resultLength = 0;
+ }
+ return NULL;
+}
+
+static void U_CALLCONV
+ucnv_io_resetAllConverters(UEnumeration *enumerator, UErrorCode *pErrorCode) {
+ *((uint16_t *)(enumerator->context)) = 0;
+}
+
+static const UEnumeration gEnumAllConverters = {
+ NULL,
+ NULL,
+ ucnv_io_closeUEnumeration,
+ ucnv_io_countAllConverters,
+ uenum_unextDefault,
+ ucnv_io_nextAllConverters,
+ ucnv_io_resetAllConverters
+};
+
+U_CAPI UEnumeration * U_EXPORT2
+ucnv_openAllNames(UErrorCode *pErrorCode) {
+ UEnumeration *myEnum = NULL;
+ if (haveAliasData(pErrorCode)) {
+ uint16_t *myContext;
+
+ myEnum = uprv_malloc(sizeof(UEnumeration));
+ if (myEnum == NULL) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memcpy(myEnum, &gEnumAllConverters, sizeof(UEnumeration));
+ myContext = uprv_malloc(sizeof(uint16_t));
+ if (myContext == NULL) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ uprv_free(myEnum);
+ return NULL;
+ }
+ *myContext = 0;
+ myEnum->context = myContext;
+ }
+ return myEnum;
+}
+
+U_CFUNC uint16_t
+ucnv_io_countKnownConverters(UErrorCode *pErrorCode) {
+ if (haveAliasData(pErrorCode)) {
+ return (uint16_t)gMainTable.converterListSize;
+ }
+ return 0;
+}
+
+/* alias table swapping ----------------------------------------------------- */
+
+typedef char * U_CALLCONV StripForCompareFn(char *dst, const char *name);
+
+/*
+ * row of a temporary array
+ *
+ * gets platform-endian charset string indexes and sorting indexes;
+ * after sorting this array by strings, the actual arrays are permutated
+ * according to the sorting indexes
+ */
+typedef struct TempRow {
+ uint16_t strIndex, sortIndex;
+} TempRow;
+
+typedef struct TempAliasTable {
+ const char *chars;
+ TempRow *rows;
+ uint16_t *resort;
+ StripForCompareFn *stripForCompare;
+} TempAliasTable;
+
+enum {
+ STACK_ROW_CAPACITY=500
+};
+
+static int32_t
+io_compareRows(const void *context, const void *left, const void *right) {
+ char strippedLeft[UCNV_MAX_CONVERTER_NAME_LENGTH],
+ strippedRight[UCNV_MAX_CONVERTER_NAME_LENGTH];
+
+ TempAliasTable *tempTable=(TempAliasTable *)context;
+ const char *chars=tempTable->chars;
+
+ return (int32_t)uprv_strcmp(tempTable->stripForCompare(strippedLeft, chars+2*((const TempRow *)left)->strIndex),
+ tempTable->stripForCompare(strippedRight, chars+2*((const TempRow *)right)->strIndex));
+}
+
+U_CAPI int32_t U_EXPORT2
+ucnv_swapAliases(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode) {
+ const UDataInfo *pInfo;
+ int32_t headerSize;
+
+ const uint16_t *inTable;
+ const uint32_t *inSectionSizes;
+ uint32_t toc[offsetsCount];
+ uint32_t offsets[offsetsCount]; /* 16-bit-addressed offsets from inTable/outTable */
+ uint32_t i, count, tocLength, topOffset;
+
+ TempRow rows[STACK_ROW_CAPACITY];
+ uint16_t resort[STACK_ROW_CAPACITY];
+ TempAliasTable tempTable;
+
+ /* udata_swapDataHeader checks the arguments */
+ headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ /* check data format and format version */
+ pInfo=(const UDataInfo *)((const char *)inData+4);
+ if(!(
+ pInfo->dataFormat[0]==0x43 && /* dataFormat="CvAl" */
+ pInfo->dataFormat[1]==0x76 &&
+ pInfo->dataFormat[2]==0x41 &&
+ pInfo->dataFormat[3]==0x6c &&
+ pInfo->formatVersion[0]==3
+ )) {
+ udata_printError(ds, "ucnv_swapAliases(): data format %02x.%02x.%02x.%02x (format version %02x) is not an alias table\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0]);
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ /* an alias table must contain at least the table of contents array */
+ if(length>=0 && (length-headerSize)<4*(1+minTocLength)) {
+ udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
+ length-headerSize);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+ inSectionSizes=(const uint32_t *)((const char *)inData+headerSize);
+ inTable=(const uint16_t *)inSectionSizes;
+ uprv_memset(toc, 0, sizeof(toc));
+ toc[tocLengthIndex]=tocLength=ds->readUInt32(inSectionSizes[tocLengthIndex]);
+ if(tocLengthreadUInt32(inSectionSizes[i]);
+ }
+
+ /* compute offsets */
+ uprv_memset(offsets, 0, sizeof(offsets));
+ offsets[converterListIndex]=2*(1+tocLength); /* count two 16-bit units per toc entry */
+ for(i=tagListIndex; i<=tocLength; ++i) {
+ offsets[i]=offsets[i-1]+toc[i-1];
+ }
+
+ /* compute the overall size of the after-header data, in numbers of 16-bit units */
+ topOffset=offsets[i-1]+toc[i-1];
+
+ if(length>=0) {
+ uint16_t *outTable;
+ const uint16_t *p, *p2;
+ uint16_t *q, *q2;
+ uint16_t oldIndex;
+
+ if((length-headerSize)<(2*(int32_t)topOffset)) {
+ udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
+ length-headerSize);
+ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+ outTable=(uint16_t *)((char *)outData+headerSize);
+
+ /* swap the entire table of contents */
+ ds->swapArray32(ds, inTable, 4*(1+tocLength), outTable, pErrorCode);
+
+ /* swap unormalized strings & normalized strings */
+ ds->swapInvChars(ds, inTable+offsets[stringTableIndex], 2*(int32_t)(toc[stringTableIndex]+toc[normalizedStringTableIndex]),
+ outTable+offsets[stringTableIndex], pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ udata_printError(ds, "ucnv_swapAliases().swapInvChars(charset names) failed\n");
+ return 0;
+ }
+
+ if(ds->inCharset==ds->outCharset) {
+ /* no need to sort, just swap all 16-bit values together */
+ ds->swapArray16(ds,
+ inTable+offsets[converterListIndex],
+ 2*(int32_t)(offsets[stringTableIndex]-offsets[converterListIndex]),
+ outTable+offsets[converterListIndex],
+ pErrorCode);
+ } else {
+ /* allocate the temporary table for sorting */
+ count=toc[aliasListIndex];
+
+ tempTable.chars=(const char *)(outTable+offsets[stringTableIndex]); /* sort by outCharset */
+
+ if(count<=STACK_ROW_CAPACITY) {
+ tempTable.rows=rows;
+ tempTable.resort=resort;
+ } else {
+ tempTable.rows=(TempRow *)uprv_malloc(count*sizeof(TempRow)+count*2);
+ if(tempTable.rows==NULL) {
+ udata_printError(ds, "ucnv_swapAliases(): unable to allocate memory for sorting tables (max length: %u)\n",
+ count);
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ tempTable.resort=(uint16_t *)(tempTable.rows+count);
+ }
+
+ if(ds->outCharset==U_ASCII_FAMILY) {
+ tempTable.stripForCompare=ucnv_io_stripASCIIForCompare;
+ } else /* U_EBCDIC_FAMILY */ {
+ tempTable.stripForCompare=ucnv_io_stripEBCDICForCompare;
+ }
+
+ /*
+ * Sort unique aliases+mapped names.
+ *
+ * We need to sort the list again by outCharset strings because they
+ * sort differently for different charset families.
+ * First we set up a temporary table with the string indexes and
+ * sorting indexes and sort that.
+ * Then we permutate and copy/swap the actual values.
+ */
+ p=inTable+offsets[aliasListIndex];
+ q=outTable+offsets[aliasListIndex];
+
+ p2=inTable+offsets[untaggedConvArrayIndex];
+ q2=outTable+offsets[untaggedConvArrayIndex];
+
+ for(i=0; ireadUInt16(p[i]);
+ tempTable.rows[i].sortIndex=(uint16_t)i;
+ }
+
+ uprv_sortArray(tempTable.rows, (int32_t)count, sizeof(TempRow),
+ io_compareRows, &tempTable,
+ FALSE, pErrorCode);
+
+ if(U_SUCCESS(*pErrorCode)) {
+ /* copy/swap/permutate items */
+ if(p!=q) {
+ for(i=0; iswapArray16(ds, p+oldIndex, 2, q+i, pErrorCode);
+ ds->swapArray16(ds, p2+oldIndex, 2, q2+i, pErrorCode);
+ }
+ } else {
+ /*
+ * If we swap in-place, then the permutation must use another
+ * temporary array (tempTable.resort)
+ * before the results are copied to the outBundle.
+ */
+ uint16_t *r=tempTable.resort;
+
+ for(i=0; iswapArray16(ds, p+oldIndex, 2, r+i, pErrorCode);
+ }
+ uprv_memcpy(q, r, 2*count);
+
+ for(i=0; iswapArray16(ds, p2+oldIndex, 2, r+i, pErrorCode);
+ }
+ uprv_memcpy(q2, r, 2*count);
+ }
+ }
+
+ if(tempTable.rows!=rows) {
+ uprv_free(tempTable.rows);
+ }
+
+ if(U_FAILURE(*pErrorCode)) {
+ udata_printError(ds, "ucnv_swapAliases().uprv_sortArray(%u items) failed\n",
+ count);
+ return 0;
+ }
+
+ /* swap remaining 16-bit values */
+ ds->swapArray16(ds,
+ inTable+offsets[converterListIndex],
+ 2*(int32_t)(offsets[aliasListIndex]-offsets[converterListIndex]),
+ outTable+offsets[converterListIndex],
+ pErrorCode);
+ ds->swapArray16(ds,
+ inTable+offsets[taggedAliasArrayIndex],
+ 2*(int32_t)(offsets[stringTableIndex]-offsets[taggedAliasArrayIndex]),
+ outTable+offsets[taggedAliasArrayIndex],
+ pErrorCode);
+ }
+ }
+
+ return headerSize+2*(int32_t)topOffset;
+}
+
+#endif
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_io.h b/Build/source/libs/icu/icu-xetex/common/ucnv_io.h
new file mode 100644
index 00000000000..060ffd05953
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_io.h
@@ -0,0 +1,125 @@
+/*
+ **********************************************************************
+ * Copyright (C) 1999-2006, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ *
+ *
+ * ucnv_io.h:
+ * defines variables and functions pertaining to converter name resolution
+ * aspect of the conversion code
+ */
+
+#ifndef UCNV_IO_H
+#define UCNV_IO_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "udataswp.h"
+
+#define UCNV_AMBIGUOUS_ALIAS_MAP_BIT 0x8000
+#define UCNV_CONTAINS_OPTION_BIT 0x4000
+#define UCNV_CONVERTER_INDEX_MASK 0xFFF
+#define UCNV_NUM_RESERVED_TAGS 2
+#define UCNV_NUM_HIDDEN_TAGS 1
+
+enum {
+ UCNV_IO_UNNORMALIZED,
+ UCNV_IO_STD_NORMALIZED,
+ UCNV_IO_NORM_TYPE_COUNT
+};
+
+typedef struct {
+ uint16_t stringNormalizationType;
+ uint16_t containsCnvOptionInfo;
+} UConverterAliasOptions;
+
+typedef struct UConverterAlias {
+ const uint16_t *converterList;
+ const uint16_t *tagList;
+ const uint16_t *aliasList;
+ const uint16_t *untaggedConvArray;
+ const uint16_t *taggedAliasArray;
+ const uint16_t *taggedAliasLists;
+ const UConverterAliasOptions *optionTable;
+ const uint16_t *stringTable;
+ const uint16_t *normalizedStringTable;
+
+ uint32_t converterListSize;
+ uint32_t tagListSize;
+ uint32_t aliasListSize;
+ uint32_t untaggedConvArraySize;
+ uint32_t taggedAliasArraySize;
+ uint32_t taggedAliasListsSize;
+ uint32_t optionTableSize;
+ uint32_t stringTableSize;
+ uint32_t normalizedStringTableSize;
+} UConverterAlias;
+
+/**
+ * \var ucnv_io_stripForCompare
+ * Remove the underscores, dashes and spaces from the name, and convert
+ * the name to lower case.
+ * @param dst The destination buffer, which is <= the buffer of name.
+ * @param dst The destination buffer, which is <= the buffer of name.
+ * @see ucnv_compareNames
+ * @return the destination buffer.
+ */
+#if U_CHARSET_FAMILY==U_ASCII_FAMILY
+# define ucnv_io_stripForCompare ucnv_io_stripASCIIForCompare
+#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+# define ucnv_io_stripForCompare ucnv_io_stripEBCDICForCompare
+#else
+# error U_CHARSET_FAMILY is not valid
+#endif
+
+U_CAPI char * U_EXPORT2
+ucnv_io_stripASCIIForCompare(char *dst, const char *name);
+
+U_CAPI char * U_EXPORT2
+ucnv_io_stripEBCDICForCompare(char *dst, const char *name);
+
+/**
+ * Map a converter alias name to a canonical converter name.
+ * The alias is searched for case-insensitively, the converter name
+ * is returned in mixed-case.
+ * Returns NULL if the alias is not found.
+ * @param alias The alias name to be searched.
+ * @param containsOption A return value stating whether the returned converter name contains an option (a comma)
+ * @param pErrorCode The error code
+ * @return the converter name in mixed-case, return NULL if the alias is not found.
+ */
+U_CFUNC const char *
+ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode);
+
+/**
+ * Return the number of all known converter names (no aliases).
+ * @param pErrorCode The error code
+ * @return the number of all aliases
+ */
+U_CFUNC uint16_t
+ucnv_io_countKnownConverters(UErrorCode *pErrorCode);
+
+/**
+ * Swap an ICU converter alias table. See implementation for details.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+ucnv_swapAliases(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+
+#endif
+
+#endif /* _UCNV_IO */
+
+/*
+ * Hey, Emacs, please set the following:
+ *
+ * Local Variables:
+ * indent-tabs-mode: nil
+ * End:
+ *
+ */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_lmb.c b/Build/source/libs/icu/icu-xetex/common/ucnv_lmb.c
new file mode 100644
index 00000000000..79606af2894
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_lmb.c
@@ -0,0 +1,1281 @@
+/*
+**********************************************************************
+* Copyright (C) 2000-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: ucnv_lmb.cpp
+* encoding: US-ASCII
+* tab size: 4 (not used)
+* indentation:4
+*
+* created on: 2000feb09
+* created by: Brendan Murray
+* extensively hacked up by: Jim Snyder-Grant
+*
+* Modification History:
+*
+* Date Name Description
+*
+* 06/20/2000 helena OS/400 port changes; mostly typecast.
+* 06/27/2000 Jim Snyder-Grant Deal with partial characters and small buffers.
+* Add comments to document LMBCS format and implementation
+* restructured order & breakdown of functions
+* 06/28/2000 helena Major rewrite for the callback API changes.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION
+
+#include "unicode/ucnv_err.h"
+#include "unicode/ucnv.h"
+#include "unicode/uset.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "ucnv_imp.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
+/*
+ LMBCS
+
+ (Lotus Multi-Byte Character Set)
+
+ LMBCS was invented in the late 1980's and is primarily used in Lotus Notes
+ databases and in Lotus 1-2-3 files. Programmers who work with the APIs
+ into these products will sometimes need to deal with strings in this format.
+
+ The code in this file provides an implementation for an ICU converter of
+ LMBCS to and from Unicode.
+
+ Since the LMBCS character set is only sparsely documented in existing
+ printed or online material, we have added extensive annotation to this
+ file to serve as a guide to understanding LMBCS.
+
+ LMBCS was originally designed with these four sometimes-competing design goals:
+
+ -Provide encodings for the characters in 12 existing national standards
+ (plus a few other characters)
+ -Minimal memory footprint
+ -Maximal speed of conversion into the existing national character sets
+ -No need to track a changing state as you interpret a string.
+
+
+ All of the national character sets LMBCS was trying to encode are 'ANSI'
+ based, in that the bytes from 0x20 - 0x7F are almost exactly the
+ same common Latin unaccented characters and symbols in all character sets.
+
+ So, in order to help meet the speed & memory design goals, the common ANSI
+ bytes from 0x20-0x7F are represented by the same single-byte values in LMBCS.
+
+ The general LMBCS code unit is from 1-3 bytes. We can describe the 3 bytes as
+ follows:
+
+ [G] D1 [D2]
+
+ That is, a sometimes-optional 'group' byte, followed by 1 and sometimes 2
+ data bytes. The maximum size of a LMBCS chjaracter is 3 bytes:
+*/
+#define ULMBCS_CHARSIZE_MAX 3
+/*
+ The single-byte values from 0x20 to 0x7F are examples of single D1 bytes.
+ We often have to figure out if byte values are below or above this, so we
+ use the ANSI nomenclature 'C0' and 'C1' to refer to the range of control
+ characters just above & below the common lower-ANSI range */
+#define ULMBCS_C0END 0x1F
+#define ULMBCS_C1START 0x80
+/*
+ Since LMBCS is always dealing in byte units. we create a local type here for
+ dealing with these units of LMBCS code units:
+
+*/
+typedef uint8_t ulmbcs_byte_t;
+
+/*
+ Most of the values less than 0x20 are reserved in LMBCS to announce
+ which national character standard is being used for the 'D' bytes.
+ In the comments we show the common name and the IBM character-set ID
+ for these character-set announcers:
+*/
+
+#define ULMBCS_GRP_L1 0x01 /* Latin-1 :ibm-850 */
+#define ULMBCS_GRP_GR 0x02 /* Greek :ibm-851 */
+#define ULMBCS_GRP_HE 0x03 /* Hebrew :ibm-1255 */
+#define ULMBCS_GRP_AR 0x04 /* Arabic :ibm-1256 */
+#define ULMBCS_GRP_RU 0x05 /* Cyrillic :ibm-1251 */
+#define ULMBCS_GRP_L2 0x06 /* Latin-2 :ibm-852 */
+#define ULMBCS_GRP_TR 0x08 /* Turkish :ibm-1254 */
+#define ULMBCS_GRP_TH 0x0B /* Thai :ibm-874 */
+#define ULMBCS_GRP_JA 0x10 /* Japanese :ibm-943 */
+#define ULMBCS_GRP_KO 0x11 /* Korean :ibm-1261 */
+#define ULMBCS_GRP_TW 0x12 /* Chinese SC :ibm-950 */
+#define ULMBCS_GRP_CN 0x13 /* Chinese TC :ibm-1386 */
+
+/*
+ So, the beginning of understanding LMBCS is that IF the first byte of a LMBCS
+ character is one of those 12 values, you can interpret the remaining bytes of
+ that character as coming from one of those character sets. Since the lower
+ ANSI bytes already are represented in single bytes, using one of the character
+ set announcers is used to announce a character that starts with a byte of
+ 0x80 or greater.
+
+ The character sets are arranged so that the single byte sets all appear
+ before the multi-byte character sets. When we need to tell whether a
+ group byte is for a single byte char set or not we use this define: */
+
+#define ULMBCS_DOUBLEOPTGROUP_START 0x10
+
+/*
+However, to fully understand LMBCS, you must also understand a series of
+exceptions & optimizations made in service of the design goals.
+
+First, those of you who are character set mavens may have noticed that
+the 'double-byte' character sets are actually multi-byte character sets
+that can have 1 or two bytes, even in the upper-ascii range. To force
+each group byte to introduce a fixed-width encoding (to make it faster to
+count characters), we use a convention of doubling up on the group byte
+to introduce any single-byte character > 0x80 in an otherwise double-byte
+character set. So, for example, the LMBCS sequence x10 x10 xAE is the
+same as '0xAE' in the Japanese code page 943.
+
+Next, you will notice that the list of group bytes has some gaps.
+These are used in various ways.
+
+We reserve a few special single byte values for common control
+characters. These are in the same place as their ANSI eqivalents for speed.
+*/
+
+#define ULMBCS_HT 0x09 /* Fixed control char - Horizontal Tab */
+#define ULMBCS_LF 0x0A /* Fixed control char - Line Feed */
+#define ULMBCS_CR 0x0D /* Fixed control char - Carriage Return */
+
+/* Then, 1-2-3 reserved a special single-byte character to put at the
+beginning of internal 'system' range names: */
+
+#define ULMBCS_123SYSTEMRANGE 0x19
+
+/* Then we needed a place to put all the other ansi control characters
+that must be moved to different values because LMBCS reserves those
+values for other purposes. To represent the control characters, we start
+with a first byte of 0xF & add the control chaarcter value as the
+second byte */
+#define ULMBCS_GRP_CTRL 0x0F
+
+/* For the C0 controls (less than 0x20), we add 0x20 to preserve the
+useful doctrine that any byte less than 0x20 in a LMBCS char must be
+the first byte of a character:*/
+#define ULMBCS_CTRLOFFSET 0x20
+
+/*
+Where to put the characters that aren't part of any of the 12 national
+character sets? The first thing that was done, in the earlier years of
+LMBCS, was to use up the spaces of the form
+
+ [G] D1,
+
+ where 'G' was one of the single-byte character groups, and
+ D1 was less than 0x80. These sequences are gathered together
+ into a Lotus-invented doublebyte character set to represent a
+ lot of stray values. Internally, in this implementation, we track this
+ as group '0', as a place to tuck this exceptions list.*/
+
+#define ULMBCS_GRP_EXCEPT 0x00
+/*
+ Finally, as the durability and usefulness of UNICODE became clear,
+ LOTUS added a new group 0x14 to hold Unicode values not otherwise
+ represented in LMBCS: */
+#define ULMBCS_GRP_UNICODE 0x14
+/* The two bytes appearing after a 0x14 are intrepreted as UFT-16 BE
+(Big-Endian) characters. The exception comes when the UTF16
+representation would have a zero as the second byte. In that case,
+'F6' is used in its place, and the bytes are swapped. (This prevents
+LMBCS from encoding any Unicode values of the form U+F6xx, but that's OK:
+0xF6xx is in the middle of the Private Use Area.)*/
+#define ULMBCS_UNICOMPATZERO 0xF6
+
+/* It is also useful in our code to have a constant for the size of
+a LMBCS char that holds a literal Unicode value */
+#define ULMBCS_UNICODE_SIZE 3
+
+/*
+To squish the LMBCS representations down even further, and to make
+translations even faster,sometimes the optimization group byte can be dropped
+from a LMBCS character. This is decided on a process-by-process basis. The
+group byte that is dropped is called the 'optimization group'.
+
+For Notes, the optimzation group is always 0x1.*/
+#define ULMBCS_DEFAULTOPTGROUP 0x1
+/* For 1-2-3 files, the optimzation group is stored in the header of the 1-2-3
+file.
+
+ In any case, when using ICU, you either pass in the
+optimization group as part of the name of the converter (LMBCS-1, LMBCS-2,
+etc.). Using plain 'LMBCS' as the name of the converter will give you
+LMBCS-1.
+
+
+*** Implementation strategy ***
+
+
+Because of the extensive use of other character sets, the LMBCS converter
+keeps a mapping between optimization groups and IBM character sets, so that
+ICU converters can be created and used as needed. */
+
+/* As you can see, even though any byte below 0x20 could be an optimization
+byte, only those at 0x13 or below can map to an actual converter. To limit
+some loops and searches, we define a value for that last group converter:*/
+
+#define ULMBCS_GRP_LAST 0x13 /* last LMBCS group that has a converter */
+
+static const char * const OptGroupByteToCPName[ULMBCS_GRP_LAST + 1] = {
+ /* 0x0000 */ "lmb-excp", /* internal home for the LOTUS exceptions list */
+ /* 0x0001 */ "ibm-850",
+ /* 0x0002 */ "ibm-851",
+ /* 0x0003 */ "windows-1255",
+ /* 0x0004 */ "windows-1256",
+ /* 0x0005 */ "windows-1251",
+ /* 0x0006 */ "ibm-852",
+ /* 0x0007 */ NULL, /* Unused */
+ /* 0x0008 */ "windows-1254",
+ /* 0x0009 */ NULL, /* Control char HT */
+ /* 0x000A */ NULL, /* Control char LF */
+ /* 0x000B */ "windows-874",
+ /* 0x000C */ NULL, /* Unused */
+ /* 0x000D */ NULL, /* Control char CR */
+ /* 0x000E */ NULL, /* Unused */
+ /* 0x000F */ NULL, /* Control chars: 0x0F20 + C0/C1 character: algorithmic */
+ /* 0x0010 */ "windows-932",
+ /* 0x0011 */ "windows-949",
+ /* 0x0012 */ "windows-950",
+ /* 0x0013 */ "windows-936"
+
+ /* The rest are null, including the 0x0014 Unicode compatibility region
+ and 0x0019, the 1-2-3 system range control char */
+};
+
+
+/* That's approximately all the data that's needed for translating
+ LMBCS to Unicode.
+
+
+However, to translate Unicode to LMBCS, we need some more support.
+
+That's because there are often more than one possible mappings from a Unicode
+code point back into LMBCS. The first thing we do is look up into a table
+to figure out if there are more than one possible mappings. This table,
+arranged by Unicode values (including ranges) either lists which group
+to use, or says that it could go into one or more of the SBCS sets, or
+into one or more of the DBCS sets. (If the character exists in both DBCS &
+SBCS, the table will place it in the SBCS sets, to make the LMBCS code point
+length as small as possible. Here's the two special markers we use to indicate
+ambiguous mappings: */
+
+#define ULMBCS_AMBIGUOUS_SBCS 0x80 /* could fit in more than one
+ LMBCS sbcs native encoding
+ (example: most accented latin) */
+#define ULMBCS_AMBIGUOUS_MBCS 0x81 /* could fit in more than one
+ LMBCS mbcs native encoding
+ (example: Unihan) */
+
+/* And here's a simple way to see if a group falls in an appropriate range */
+#define ULMBCS_AMBIGUOUS_MATCH(agroup, xgroup) \
+ ((((agroup) == ULMBCS_AMBIGUOUS_SBCS) && \
+ (xgroup) < ULMBCS_DOUBLEOPTGROUP_START) || \
+ (((agroup) == ULMBCS_AMBIGUOUS_MBCS) && \
+ (xgroup) >= ULMBCS_DOUBLEOPTGROUP_START))
+
+
+/* The table & some code to use it: */
+
+
+static const struct _UniLMBCSGrpMap
+{
+ const UChar uniStartRange;
+ const UChar uniEndRange;
+ const ulmbcs_byte_t GrpType;
+} UniLMBCSGrpMap[]
+=
+{
+
+ {0x0001, 0x001F, ULMBCS_GRP_CTRL},
+ {0x0080, 0x009F, ULMBCS_GRP_CTRL},
+ {0x00A0, 0x01CD, ULMBCS_AMBIGUOUS_SBCS},
+ {0x01CE, 0x01CE, ULMBCS_GRP_TW },
+ {0x01CF, 0x02B9, ULMBCS_AMBIGUOUS_SBCS},
+ {0x02BA, 0x02BA, ULMBCS_GRP_CN},
+ {0x02BC, 0x02C8, ULMBCS_AMBIGUOUS_SBCS},
+ {0x02C9, 0x02D0, ULMBCS_AMBIGUOUS_MBCS},
+ {0x02D8, 0x02DD, ULMBCS_AMBIGUOUS_SBCS},
+ {0x0384, 0x03CE, ULMBCS_AMBIGUOUS_SBCS},
+ {0x0400, 0x044E, ULMBCS_GRP_RU},
+ {0x044F, 0x044F, ULMBCS_AMBIGUOUS_MBCS},
+ {0x0450, 0x0491, ULMBCS_GRP_RU},
+ {0x05B0, 0x05F2, ULMBCS_GRP_HE},
+ {0x060C, 0x06AF, ULMBCS_GRP_AR},
+ {0x0E01, 0x0E5B, ULMBCS_GRP_TH},
+ {0x200C, 0x200F, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2010, 0x2010, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2013, 0x2015, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2016, 0x2016, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2017, 0x2024, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2025, 0x2025, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2026, 0x2026, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2027, 0x2027, ULMBCS_GRP_CN},
+ {0x2030, 0x2033, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2035, 0x2035, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2039, 0x203A, ULMBCS_AMBIGUOUS_SBCS},
+ {0x203B, 0x203B, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2074, 0x2074, ULMBCS_GRP_KO},
+ {0x207F, 0x207F, ULMBCS_GRP_EXCEPT},
+ {0x2081, 0x2084, ULMBCS_GRP_KO},
+ {0x20A4, 0x20AC, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2103, 0x2109, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2111, 0x2126, ULMBCS_AMBIGUOUS_SBCS},
+ {0x212B, 0x212B, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2135, 0x2135, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2153, 0x2154, ULMBCS_GRP_KO},
+ {0x215B, 0x215E, ULMBCS_GRP_EXCEPT},
+ {0x2160, 0x2179, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2190, 0x2195, ULMBCS_GRP_EXCEPT},
+ {0x2196, 0x2199, ULMBCS_AMBIGUOUS_MBCS},
+ {0x21A8, 0x21A8, ULMBCS_GRP_EXCEPT},
+ {0x21B8, 0x21B9, ULMBCS_GRP_CN},
+ {0x21D0, 0x21D5, ULMBCS_GRP_EXCEPT},
+ {0x21E7, 0x21E7, ULMBCS_GRP_CN},
+ {0x2200, 0x220B, ULMBCS_GRP_EXCEPT},
+ {0x220F, 0x2215, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2219, 0x2220, ULMBCS_GRP_EXCEPT},
+ {0x2223, 0x2228, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2229, 0x222B, ULMBCS_GRP_EXCEPT},
+ {0x222C, 0x223D, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2245, 0x2248, ULMBCS_GRP_EXCEPT},
+ {0x224C, 0x224C, ULMBCS_GRP_TW},
+ {0x2252, 0x2252, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2260, 0x2265, ULMBCS_GRP_EXCEPT},
+ {0x2266, 0x226F, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2282, 0x2297, ULMBCS_GRP_EXCEPT},
+ {0x2299, 0x22BF, ULMBCS_AMBIGUOUS_MBCS},
+ {0x22C0, 0x22C0, ULMBCS_GRP_EXCEPT},
+ {0x2310, 0x2310, ULMBCS_GRP_EXCEPT},
+ {0x2312, 0x2312, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2318, 0x2321, ULMBCS_GRP_EXCEPT},
+ {0x2318, 0x2321, ULMBCS_GRP_CN},
+ {0x2460, 0x24E9, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2500, 0x2500, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2501, 0x2501, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2502, 0x2502, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2503, 0x2503, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2504, 0x2505, ULMBCS_GRP_TW},
+ {0x2506, 0x2665, ULMBCS_AMBIGUOUS_MBCS},
+ {0x2666, 0x2666, ULMBCS_GRP_EXCEPT},
+ {0x2666, 0x2666, ULMBCS_GRP_EXCEPT},
+ {0x2667, 0x2E7F, ULMBCS_AMBIGUOUS_SBCS},
+ {0x2E80, 0xF861, ULMBCS_AMBIGUOUS_MBCS},
+ {0xF862, 0xF8FF, ULMBCS_GRP_EXCEPT},
+ {0xF900, 0xFA2D, ULMBCS_AMBIGUOUS_MBCS},
+ {0xFB00, 0xFEFF, ULMBCS_AMBIGUOUS_SBCS},
+ {0xFF01, 0xFFEE, ULMBCS_AMBIGUOUS_MBCS},
+ {0xFFFF, 0xFFFF, ULMBCS_GRP_UNICODE}
+};
+
+static ulmbcs_byte_t
+FindLMBCSUniRange(UChar uniChar)
+{
+ const struct _UniLMBCSGrpMap * pTable = UniLMBCSGrpMap;
+
+ while (uniChar > pTable->uniEndRange)
+ {
+ pTable++;
+ }
+
+ if (uniChar >= pTable->uniStartRange)
+ {
+ return pTable->GrpType;
+ }
+ return ULMBCS_GRP_UNICODE;
+}
+
+/*
+We also ask the creator of a converter to send in a preferred locale
+that we can use in resolving ambiguous mappings. They send the locale
+in as a string, and we map it, if possible, to one of the
+LMBCS groups. We use this table, and the associated code, to
+do the lookup: */
+
+/**************************************************
+ This table maps locale ID's to LMBCS opt groups.
+ The default return is group 0x01. Note that for
+ performance reasons, the table is sorted in
+ increasing alphabetic order, with the notable
+ exception of zhTW. This is to force the check
+ for Traditonal Chinese before dropping back to
+ Simplified.
+
+ Note too that the Latin-1 groups have been
+ commented out because it's the default, and
+ this shortens the table, allowing a serial
+ search to go quickly.
+ *************************************************/
+
+static const struct _LocaleLMBCSGrpMap
+{
+ const char *LocaleID;
+ const ulmbcs_byte_t OptGroup;
+} LocaleLMBCSGrpMap[] =
+{
+ {"ar", ULMBCS_GRP_AR},
+ {"be", ULMBCS_GRP_RU},
+ {"bg", ULMBCS_GRP_L2},
+ /* {"ca", ULMBCS_GRP_L1}, */
+ {"cs", ULMBCS_GRP_L2},
+ /* {"da", ULMBCS_GRP_L1}, */
+ /* {"de", ULMBCS_GRP_L1}, */
+ {"el", ULMBCS_GRP_GR},
+ /* {"en", ULMBCS_GRP_L1}, */
+ /* {"es", ULMBCS_GRP_L1}, */
+ /* {"et", ULMBCS_GRP_L1}, */
+ /* {"fi", ULMBCS_GRP_L1}, */
+ /* {"fr", ULMBCS_GRP_L1}, */
+ {"he", ULMBCS_GRP_HE},
+ {"hu", ULMBCS_GRP_L2},
+ /* {"is", ULMBCS_GRP_L1}, */
+ /* {"it", ULMBCS_GRP_L1}, */
+ {"iw", ULMBCS_GRP_HE},
+ {"ja", ULMBCS_GRP_JA},
+ {"ko", ULMBCS_GRP_KO},
+ /* {"lt", ULMBCS_GRP_L1}, */
+ /* {"lv", ULMBCS_GRP_L1}, */
+ {"mk", ULMBCS_GRP_RU},
+ /* {"nl", ULMBCS_GRP_L1}, */
+ /* {"no", ULMBCS_GRP_L1}, */
+ {"pl", ULMBCS_GRP_L2},
+ /* {"pt", ULMBCS_GRP_L1}, */
+ {"ro", ULMBCS_GRP_L2},
+ {"ru", ULMBCS_GRP_RU},
+ {"sh", ULMBCS_GRP_L2},
+ {"sk", ULMBCS_GRP_L2},
+ {"sl", ULMBCS_GRP_L2},
+ {"sq", ULMBCS_GRP_L2},
+ {"sr", ULMBCS_GRP_RU},
+ /* {"sv", ULMBCS_GRP_L1}, */
+ {"th", ULMBCS_GRP_TH},
+ {"tr", ULMBCS_GRP_TR},
+ {"uk", ULMBCS_GRP_RU},
+ /* {"vi", ULMBCS_GRP_L1}, */
+ {"zhTW", ULMBCS_GRP_TW},
+ {"zh", ULMBCS_GRP_CN},
+ {NULL, ULMBCS_GRP_L1}
+};
+
+
+static ulmbcs_byte_t
+FindLMBCSLocale(const char *LocaleID)
+{
+ const struct _LocaleLMBCSGrpMap *pTable = LocaleLMBCSGrpMap;
+
+ if ((!LocaleID) || (!*LocaleID))
+ {
+ return 0;
+ }
+
+ while (pTable->LocaleID)
+ {
+ if (*pTable->LocaleID == *LocaleID) /* Check only first char for speed */
+ {
+ /* First char matches - check whole name, for entry-length */
+ if (uprv_strncmp(pTable->LocaleID, LocaleID, strlen(pTable->LocaleID)) == 0)
+ return pTable->OptGroup;
+ }
+ else
+ if (*pTable->LocaleID > *LocaleID) /* Sorted alphabetically - exit */
+ break;
+ pTable++;
+ }
+ return ULMBCS_GRP_L1;
+}
+
+
+/*
+ Before we get to the main body of code, here's how we hook up to the rest
+ of ICU. ICU converters are required to define a structure that includes
+ some function pointers, and some common data, in the style of a C++
+ vtable. There is also room in there for converter-specific data. LMBCS
+ uses that converter-specific data to keep track of the 12 subconverters
+ we use, the optimization group, and the group (if any) that matches the
+ locale. We have one structure instantiated for each of the 12 possible
+ optimization groups. To avoid typos & to avoid boring the reader, we
+ put the declarations of these structures and functions into macros. To see
+ the definitions of these structures, see unicode\ucnv_bld.h
+*/
+
+typedef struct
+ {
+ UConverterSharedData *OptGrpConverter[ULMBCS_GRP_LAST+1]; /* Converter per Opt. grp. */
+ uint8_t OptGroup; /* default Opt. grp. for this LMBCS session */
+ uint8_t localeConverterIndex; /* reasonable locale match for index */
+ }
+UConverterDataLMBCS;
+
+
+#define DECLARE_LMBCS_DATA(n) \
+static const UConverterImpl _LMBCSImpl##n={\
+ UCNV_LMBCS_##n,\
+ NULL,NULL,\
+ _LMBCSOpen##n,\
+ _LMBCSClose,\
+ NULL,\
+ _LMBCSToUnicodeWithOffsets,\
+ _LMBCSToUnicodeWithOffsets,\
+ _LMBCSFromUnicode,\
+ _LMBCSFromUnicode,\
+ NULL,\
+ NULL,\
+ NULL,\
+ NULL,\
+ _LMBCSSafeClone,\
+ _LMBCSGetUnicodeSet\
+};\
+static const UConverterStaticData _LMBCSStaticData##n={\
+ sizeof(UConverterStaticData),\
+ "LMBCS-" #n,\
+ 0, UCNV_IBM, UCNV_LMBCS_##n, 1, 3,\
+ { 0x3f, 0, 0, 0 },1,FALSE,FALSE,0,0,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} \
+};\
+const UConverterSharedData _LMBCSData##n={\
+ sizeof(UConverterSharedData), ~((uint32_t) 0),\
+ NULL, NULL, &_LMBCSStaticData##n, FALSE, &_LMBCSImpl##n, \
+ 0 \
+};
+
+ /* The only function we needed to duplicate 12 times was the 'open'
+function, which will do basically the same thing except set a different
+optimization group. So, we put the common stuff into a worker function,
+and set up another macro to stamp out the 12 open functions:*/
+#define DEFINE_LMBCS_OPEN(n) \
+static void \
+ _LMBCSOpen##n(UConverter* _this,const char* name,const char* locale,uint32_t options,UErrorCode* err) \
+{ _LMBCSOpenWorker(_this, name,locale,options, err, n);}
+
+
+
+/* Here's the open worker & the common close function */
+static void
+_LMBCSOpenWorker(UConverter* _this,
+ const char* name,
+ const char* locale,
+ uint32_t options,
+ UErrorCode* err,
+ ulmbcs_byte_t OptGroup
+ )
+{
+ UConverterDataLMBCS * extraInfo = (UConverterDataLMBCS*)uprv_malloc (sizeof (UConverterDataLMBCS));
+ if(extraInfo != NULL)
+ {
+ ulmbcs_byte_t i;
+
+ uprv_memset(extraInfo, 0, sizeof(UConverterDataLMBCS));
+
+ for (i=0; i <= ULMBCS_GRP_LAST && U_SUCCESS(*err); i++)
+ {
+ if(OptGroupByteToCPName[i] != NULL) {
+ extraInfo->OptGrpConverter[i] = ucnv_loadSharedData(OptGroupByteToCPName[i], NULL, err);
+ }
+ }
+
+ if(U_SUCCESS(*err)) {
+ extraInfo->OptGroup = OptGroup;
+ extraInfo->localeConverterIndex = FindLMBCSLocale(locale);
+ } else {
+ /* one of the subconverters could not be loaded, unload the previous ones */
+ while(i > 0) {
+ if(extraInfo->OptGrpConverter[--i] != NULL) {
+ ucnv_unloadSharedDataIfReady(extraInfo->OptGrpConverter[i]);
+ extraInfo->OptGrpConverter[i] = NULL;
+ }
+ }
+ }
+ }
+ else
+ {
+ *err = U_MEMORY_ALLOCATION_ERROR;
+ }
+ _this->extraInfo = extraInfo;
+}
+
+static void
+_LMBCSClose(UConverter * _this)
+{
+ if (_this->extraInfo != NULL)
+ {
+ ulmbcs_byte_t Ix;
+ UConverterDataLMBCS * extraInfo = (UConverterDataLMBCS *) _this->extraInfo;
+
+ for (Ix=0; Ix <= ULMBCS_GRP_LAST; Ix++)
+ {
+ if (extraInfo->OptGrpConverter[Ix] != NULL)
+ ucnv_unloadSharedDataIfReady(extraInfo->OptGrpConverter[Ix]);
+ }
+ if (!_this->isExtraLocal) {
+ uprv_free (_this->extraInfo);
+ }
+ }
+}
+
+typedef struct LMBCSClone {
+ UConverter cnv;
+ UConverterDataLMBCS lmbcs;
+} LMBCSClone;
+
+static UConverter *
+_LMBCSSafeClone(const UConverter *cnv,
+ void *stackBuffer,
+ int32_t *pBufferSize,
+ UErrorCode *status) {
+ LMBCSClone *newLMBCS;
+ UConverterDataLMBCS *extraInfo;
+ int32_t i;
+
+ if(*pBufferSize<=0) {
+ *pBufferSize=(int32_t)sizeof(LMBCSClone);
+ return NULL;
+ }
+
+ extraInfo=(UConverterDataLMBCS *)cnv->extraInfo;
+ newLMBCS=(LMBCSClone *)stackBuffer;
+
+ /* ucnv.c/ucnv_safeClone() copied the main UConverter already */
+
+ uprv_memcpy(&newLMBCS->lmbcs, extraInfo, sizeof(UConverterDataLMBCS));
+
+ /* share the subconverters */
+ for(i = 0; i <= ULMBCS_GRP_LAST; ++i) {
+ if(extraInfo->OptGrpConverter[i] != NULL) {
+ ucnv_incrementRefCount(extraInfo->OptGrpConverter[i]);
+ }
+ }
+
+ newLMBCS->cnv.extraInfo = &newLMBCS->lmbcs;
+ newLMBCS->cnv.isExtraLocal = TRUE;
+ return &newLMBCS->cnv;
+}
+
+static void
+_LMBCSGetUnicodeSet(const UConverter *cnv,
+ const USetAdder *sa,
+ UConverterUnicodeSet which,
+ UErrorCode *pErrorCode) {
+ /* all but U+F6xx, see LMBCS explanation above (search for F6xx) */
+ sa->addRange(sa->set, 0, 0xf5ff);
+ sa->addRange(sa->set, 0xf700, 0x10ffff);
+}
+
+/*
+ Here's the basic helper function that we use when converting from
+ Unicode to LMBCS, and we suspect that a Unicode character will fit into
+ one of the 12 groups. The return value is the number of bytes written
+ starting at pStartLMBCS (if any).
+*/
+
+static size_t
+LMBCSConversionWorker (
+ UConverterDataLMBCS * extraInfo, /* subconverters, opt & locale groups */
+ ulmbcs_byte_t group, /* The group to try */
+ ulmbcs_byte_t * pStartLMBCS, /* where to put the results */
+ UChar * pUniChar, /* The input unicode character */
+ ulmbcs_byte_t * lastConverterIndex, /* output: track last successful group used */
+ UBool * groups_tried /* output: track any unsuccessful groups */
+)
+{
+ ulmbcs_byte_t * pLMBCS = pStartLMBCS;
+ UConverterSharedData * xcnv = extraInfo->OptGrpConverter[group];
+
+ int bytesConverted;
+ uint32_t value;
+ ulmbcs_byte_t firstByte;
+
+ U_ASSERT(xcnv);
+ U_ASSERT(group 0) {
+ firstByte = (ulmbcs_byte_t)(value >> ((bytesConverted - 1) * 8));
+ } else {
+ /* most common failure mode is an unassigned character */
+ groups_tried[group] = TRUE;
+ return 0;
+ }
+
+ *lastConverterIndex = group;
+
+ /* All initial byte values in lower ascii range should have been caught by now,
+ except with the exception group.
+ */
+ U_ASSERT((firstByte <= ULMBCS_C0END) || (firstByte >= ULMBCS_C1START) || (group == ULMBCS_GRP_EXCEPT));
+
+ /* use converted data: first write 0, 1 or two group bytes */
+ if (group != ULMBCS_GRP_EXCEPT && extraInfo->OptGroup != group)
+ {
+ *pLMBCS++ = group;
+ if (bytesConverted == 1 && group >= ULMBCS_DOUBLEOPTGROUP_START)
+ {
+ *pLMBCS++ = group;
+ }
+ }
+
+ /* don't emit control chars */
+ if ( bytesConverted == 1 && firstByte < 0x20 )
+ return 0;
+
+
+ /* then move over the converted data */
+ switch(bytesConverted)
+ {
+ case 4:
+ *pLMBCS++ = (ulmbcs_byte_t)(value >> 24);
+ case 3:
+ *pLMBCS++ = (ulmbcs_byte_t)(value >> 16);
+ case 2:
+ *pLMBCS++ = (ulmbcs_byte_t)(value >> 8);
+ case 1:
+ *pLMBCS++ = (ulmbcs_byte_t)value;
+ default:
+ /* will never occur */
+ break;
+ }
+
+ return (pLMBCS - pStartLMBCS);
+}
+
+
+/* This is a much simpler version of above, when we
+know we are writing LMBCS using the Unicode group
+*/
+static size_t
+LMBCSConvertUni(ulmbcs_byte_t * pLMBCS, UChar uniChar)
+{
+ /* encode into LMBCS Unicode range */
+ uint8_t LowCh = (uint8_t)(uniChar & 0x00FF);
+ uint8_t HighCh = (uint8_t)(uniChar >> 8);
+
+ *pLMBCS++ = ULMBCS_GRP_UNICODE;
+
+ if (LowCh == 0)
+ {
+ *pLMBCS++ = ULMBCS_UNICOMPATZERO;
+ *pLMBCS++ = HighCh;
+ }
+ else
+ {
+ *pLMBCS++ = HighCh;
+ *pLMBCS++ = LowCh;
+ }
+ return ULMBCS_UNICODE_SIZE;
+}
+
+
+
+/* The main Unicode to LMBCS conversion function */
+static void
+_LMBCSFromUnicode(UConverterFromUnicodeArgs* args,
+ UErrorCode* err)
+{
+ ulmbcs_byte_t lastConverterIndex = 0;
+ UChar uniChar;
+ ulmbcs_byte_t LMBCS[ULMBCS_CHARSIZE_MAX];
+ ulmbcs_byte_t * pLMBCS;
+ int bytes_written;
+ UBool groups_tried[ULMBCS_GRP_LAST+1];
+ UConverterDataLMBCS * extraInfo = (UConverterDataLMBCS *) args->converter->extraInfo;
+ int sourceIndex = 0;
+
+
+ /* Basic strategy: attempt to fill in local LMBCS 1-char buffer.(LMBCS)
+ If that succeeds, see if it will all fit into the target & copy it over
+ if it does.
+
+ We try conversions in the following order:
+
+ 1. Single-byte ascii & special fixed control chars (&null)
+ 2. Look up group in table & try that (could be
+ A) Unicode group
+ B) control group,
+ C) national encoding,
+ or ambiguous SBCS or MBCS group (on to step 4...)
+
+ 3. If its ambiguous, try this order:
+ A) The optimization group
+ B) The locale group
+ C) The last group that succeeded with this string.
+ D) every other group that's relevent (single or double)
+ E) If its single-byte ambiguous, try the exceptions group
+
+ 4. And as a grand fallback: Unicode
+ */
+
+ while (args->source < args->sourceLimit && !U_FAILURE(*err))
+ {
+ if (args->target >= args->targetLimit)
+ {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ uniChar = *(args->source);
+ bytes_written = 0;
+ pLMBCS = LMBCS;
+
+ /* check cases in rough order of how common they are, for speed */
+
+ /* single byte matches: strategy 1 */
+
+ if (((uniChar > ULMBCS_C0END) && (uniChar < ULMBCS_C1START)) ||
+ uniChar == 0 || uniChar == ULMBCS_HT || uniChar == ULMBCS_CR ||
+ uniChar == ULMBCS_LF || uniChar == ULMBCS_123SYSTEMRANGE
+ )
+ {
+ *pLMBCS++ = (ulmbcs_byte_t ) uniChar;
+ bytes_written = 1;
+ }
+
+
+ if (!bytes_written)
+ {
+ /* Check by UNICODE range (Strategy 2) */
+ ulmbcs_byte_t group = FindLMBCSUniRange(uniChar);
+
+ if (group == ULMBCS_GRP_UNICODE) /* (Strategy 2A) */
+ {
+ pLMBCS += LMBCSConvertUni(pLMBCS,uniChar);
+
+ bytes_written = pLMBCS - LMBCS;
+ }
+ else if (group == ULMBCS_GRP_CTRL) /* (Strategy 2B) */
+ {
+ /* Handle control characters here */
+ if (uniChar <= ULMBCS_C0END)
+ {
+ *pLMBCS++ = ULMBCS_GRP_CTRL;
+ *pLMBCS++ = (ulmbcs_byte_t)(ULMBCS_CTRLOFFSET + uniChar);
+ }
+ else if (uniChar >= ULMBCS_C1START && uniChar <= ULMBCS_C1START + ULMBCS_CTRLOFFSET)
+ {
+ *pLMBCS++ = ULMBCS_GRP_CTRL;
+ *pLMBCS++ = (ulmbcs_byte_t ) (uniChar & 0x00FF);
+ }
+ bytes_written = pLMBCS - LMBCS;
+ }
+ else if (group < ULMBCS_GRP_UNICODE) /* (Strategy 2C) */
+ {
+ /* a specific converter has been identified - use it */
+ bytes_written = LMBCSConversionWorker (
+ extraInfo, group, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+ }
+ if (!bytes_written) /* the ambiguous group cases (Strategy 3) */
+ {
+ uprv_memset(groups_tried, 0, sizeof(groups_tried));
+
+ /* check for non-default optimization group (Strategy 3A )*/
+ if (extraInfo->OptGroup != 1
+ && ULMBCS_AMBIGUOUS_MATCH(group, extraInfo->OptGroup))
+ {
+ bytes_written = LMBCSConversionWorker (extraInfo,
+ extraInfo->OptGroup, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+ }
+ /* check for locale optimization group (Strategy 3B) */
+ if (!bytes_written
+ && (extraInfo->localeConverterIndex)
+ && (ULMBCS_AMBIGUOUS_MATCH(group, extraInfo->localeConverterIndex)))
+ {
+ bytes_written = LMBCSConversionWorker (extraInfo,
+ extraInfo->localeConverterIndex, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+ }
+ /* check for last optimization group used for this string (Strategy 3C) */
+ if (!bytes_written
+ && (lastConverterIndex)
+ && (ULMBCS_AMBIGUOUS_MATCH(group, lastConverterIndex)))
+ {
+ bytes_written = LMBCSConversionWorker (extraInfo,
+ lastConverterIndex, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+
+ }
+ if (!bytes_written)
+ {
+ /* just check every possible matching converter (Strategy 3D) */
+ ulmbcs_byte_t grp_start;
+ ulmbcs_byte_t grp_end;
+ ulmbcs_byte_t grp_ix;
+ grp_start = (ulmbcs_byte_t)((group == ULMBCS_AMBIGUOUS_MBCS)
+ ? ULMBCS_DOUBLEOPTGROUP_START
+ : ULMBCS_GRP_L1);
+ grp_end = (ulmbcs_byte_t)((group == ULMBCS_AMBIGUOUS_MBCS)
+ ? ULMBCS_GRP_LAST
+ : ULMBCS_GRP_TH);
+ for (grp_ix = grp_start;
+ grp_ix <= grp_end && !bytes_written;
+ grp_ix++)
+ {
+ if (extraInfo->OptGrpConverter [grp_ix] && !groups_tried [grp_ix])
+ {
+ bytes_written = LMBCSConversionWorker (extraInfo,
+ grp_ix, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+ }
+ }
+ /* a final conversion fallback to the exceptions group if its likely
+ to be single byte (Strategy 3E) */
+ if (!bytes_written && grp_start == ULMBCS_GRP_L1)
+ {
+ bytes_written = LMBCSConversionWorker (extraInfo,
+ ULMBCS_GRP_EXCEPT, pLMBCS, &uniChar,
+ &lastConverterIndex, groups_tried);
+ }
+ }
+ /* all of our other strategies failed. Fallback to Unicode. (Strategy 4)*/
+ if (!bytes_written)
+ {
+
+ pLMBCS += LMBCSConvertUni(pLMBCS, uniChar);
+ bytes_written = pLMBCS - LMBCS;
+ }
+ }
+ }
+
+ /* we have a translation. increment source and write as much as posible to target */
+ args->source++;
+ pLMBCS = LMBCS;
+ while (args->target < args->targetLimit && bytes_written--)
+ {
+ *(args->target)++ = *pLMBCS++;
+ if (args->offsets)
+ {
+ *(args->offsets)++ = sourceIndex;
+ }
+ }
+ sourceIndex++;
+ if (bytes_written > 0)
+ {
+ /* write any bytes that didn't fit in target to the error buffer,
+ common code will move this to target if we get called back with
+ enough target room
+ */
+ uint8_t * pErrorBuffer = args->converter->charErrorBuffer;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ args->converter->charErrorBufferLength = (int8_t)bytes_written;
+ while (bytes_written--)
+ {
+ *pErrorBuffer++ = *pLMBCS++;
+ }
+ }
+ }
+}
+
+
+/* Now, the Unicode from LMBCS section */
+
+
+/* A function to call when we are looking at the Unicode group byte in LMBCS */
+static UChar
+GetUniFromLMBCSUni(char const ** ppLMBCSin) /* Called with LMBCS-style Unicode byte stream */
+{
+ uint8_t HighCh = *(*ppLMBCSin)++; /* Big-endian Unicode in LMBCS compatibility group*/
+ uint8_t LowCh = *(*ppLMBCSin)++;
+
+ if (HighCh == ULMBCS_UNICOMPATZERO )
+ {
+ HighCh = LowCh;
+ LowCh = 0; /* zero-byte in LSB special character */
+ }
+ return (UChar)((HighCh << 8) | LowCh);
+}
+
+
+
+/* CHECK_SOURCE_LIMIT: Helper macro to verify that there are at least'index'
+ bytes left in source up to sourceLimit.Errors appropriately if not.
+ If we reach the limit, then update the source pointer to there to consume
+ all input as required by ICU converter semantics.
+*/
+
+#define CHECK_SOURCE_LIMIT(index) \
+ if (args->source+index > args->sourceLimit){\
+ *err = U_TRUNCATED_CHAR_FOUND;\
+ args->source = args->sourceLimit;\
+ return 0xffff;}
+
+/* Return the Unicode representation for the current LMBCS character */
+
+static UChar32
+_LMBCSGetNextUCharWorker(UConverterToUnicodeArgs* args,
+ UErrorCode* err)
+{
+ UChar32 uniChar = 0; /* an output UNICODE char */
+ ulmbcs_byte_t CurByte; /* A byte from the input stream */
+
+ /* error check */
+ if (args->source >= args->sourceLimit)
+ {
+ *err = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0xffff;
+ }
+ /* Grab first byte & save address for error recovery */
+ CurByte = *((ulmbcs_byte_t *) (args->source++));
+
+ /*
+ * at entry of each if clause:
+ * 1. 'CurByte' points at the first byte of a LMBCS character
+ * 2. '*source'points to the next byte of the source stream after 'CurByte'
+ *
+ * the job of each if clause is:
+ * 1. set '*source' to point at the beginning of next char (nop if LMBCS char is only 1 byte)
+ * 2. set 'uniChar' up with the right Unicode value, or set 'err' appropriately
+ */
+
+ /* First lets check the simple fixed values. */
+
+ if(((CurByte > ULMBCS_C0END) && (CurByte < ULMBCS_C1START)) /* ascii range */
+ || (CurByte == 0)
+ || CurByte == ULMBCS_HT || CurByte == ULMBCS_CR
+ || CurByte == ULMBCS_LF || CurByte == ULMBCS_123SYSTEMRANGE)
+ {
+ uniChar = CurByte;
+ }
+ else
+ {
+ UConverterDataLMBCS * extraInfo;
+ ulmbcs_byte_t group;
+ UConverterSharedData *cnv;
+
+ if (CurByte == ULMBCS_GRP_CTRL) /* Control character group - no opt group update */
+ {
+ ulmbcs_byte_t C0C1byte;
+ CHECK_SOURCE_LIMIT(1);
+ C0C1byte = *(args->source)++;
+ uniChar = (C0C1byte < ULMBCS_C1START) ? C0C1byte - ULMBCS_CTRLOFFSET : C0C1byte;
+ }
+ else
+ if (CurByte == ULMBCS_GRP_UNICODE) /* Unicode compatibility group: BigEndian UTF16 */
+ {
+ CHECK_SOURCE_LIMIT(2);
+
+ /* don't check for error indicators fffe/ffff below */
+ return GetUniFromLMBCSUni(&(args->source));
+ }
+ else if (CurByte <= ULMBCS_CTRLOFFSET)
+ {
+ group = CurByte; /* group byte is in the source */
+ extraInfo = (UConverterDataLMBCS *) args->converter->extraInfo;
+ if (group > ULMBCS_GRP_LAST || (cnv = extraInfo->OptGrpConverter[group]) == NULL)
+ {
+ /* this is not a valid group byte - no converter*/
+ *err = U_INVALID_CHAR_FOUND;
+ }
+ else if (group >= ULMBCS_DOUBLEOPTGROUP_START) /* double byte conversion */
+ {
+
+ CHECK_SOURCE_LIMIT(2);
+
+ /* check for LMBCS doubled-group-byte case */
+ if (*args->source == group) {
+ /* single byte */
+ ++args->source;
+ uniChar = ucnv_MBCSSimpleGetNextUChar(cnv, args->source, 1, FALSE);
+ ++args->source;
+ } else {
+ /* double byte */
+ uniChar = ucnv_MBCSSimpleGetNextUChar(cnv, args->source, 2, FALSE);
+ args->source += 2;
+ }
+ }
+ else { /* single byte conversion */
+ CHECK_SOURCE_LIMIT(1);
+ CurByte = *(args->source)++;
+
+ if (CurByte >= ULMBCS_C1START)
+ {
+ uniChar = _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(cnv, CurByte);
+ }
+ else
+ {
+ /* The non-optimizable oddballs where there is an explicit byte
+ * AND the second byte is not in the upper ascii range
+ */
+ char bytes[2];
+
+ extraInfo = (UConverterDataLMBCS *) args->converter->extraInfo;
+ cnv = extraInfo->OptGrpConverter [ULMBCS_GRP_EXCEPT];
+
+ /* Lookup value must include opt group */
+ bytes[0] = group;
+ bytes[1] = CurByte;
+ uniChar = ucnv_MBCSSimpleGetNextUChar(cnv, bytes, 2, FALSE);
+ }
+ }
+ }
+ else if (CurByte >= ULMBCS_C1START) /* group byte is implicit */
+ {
+ extraInfo = (UConverterDataLMBCS *) args->converter->extraInfo;
+ group = extraInfo->OptGroup;
+ cnv = extraInfo->OptGrpConverter[group];
+ if (group >= ULMBCS_DOUBLEOPTGROUP_START) /* double byte conversion */
+ {
+ if (!ucnv_MBCSIsLeadByte(cnv, CurByte))
+ {
+ CHECK_SOURCE_LIMIT(0);
+
+ /* let the MBCS conversion consume CurByte again */
+ uniChar = ucnv_MBCSSimpleGetNextUChar(cnv, args->source - 1, 1, FALSE);
+ }
+ else
+ {
+ CHECK_SOURCE_LIMIT(1);
+ /* let the MBCS conversion consume CurByte again */
+ uniChar = ucnv_MBCSSimpleGetNextUChar(cnv, args->source - 1, 2, FALSE);
+ ++args->source;
+ }
+ }
+ else /* single byte conversion */
+ {
+ uniChar = _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(cnv, CurByte);
+ }
+ }
+ }
+ return uniChar;
+}
+
+
+/* The exported function that converts lmbcs to one or more
+ UChars - currently UTF-16
+*/
+static void
+_LMBCSToUnicodeWithOffsets(UConverterToUnicodeArgs* args,
+ UErrorCode* err)
+{
+ char LMBCS [ULMBCS_CHARSIZE_MAX];
+ UChar uniChar; /* one output UNICODE char */
+ const char * saveSource; /* beginning of current code point */
+ const char * pStartLMBCS = args->source; /* beginning of whole string */
+ const char * errSource = NULL; /* pointer to actual input in case an error occurs */
+ int8_t savebytes = 0;
+
+ /* Process from source to limit, or until error */
+ while (U_SUCCESS(*err) && args->sourceLimit > args->source && args->targetLimit > args->target)
+ {
+ saveSource = args->source; /* beginning of current code point */
+
+ if (args->converter->toULength) /* reassemble char from previous call */
+ {
+ const char *saveSourceLimit;
+ size_t size_old = args->converter->toULength;
+
+ /* limit from source is either remainder of temp buffer, or user limit on source */
+ size_t size_new_maybe_1 = sizeof(LMBCS) - size_old;
+ size_t size_new_maybe_2 = args->sourceLimit - args->source;
+ size_t size_new = (size_new_maybe_1 < size_new_maybe_2) ? size_new_maybe_1 : size_new_maybe_2;
+
+
+ uprv_memcpy(LMBCS, args->converter->toUBytes, size_old);
+ uprv_memcpy(LMBCS + size_old, args->source, size_new);
+ saveSourceLimit = args->sourceLimit;
+ args->source = errSource = LMBCS;
+ args->sourceLimit = LMBCS+size_old+size_new;
+ savebytes = (int8_t)(size_old+size_new);
+ uniChar = (UChar) _LMBCSGetNextUCharWorker(args, err);
+ args->source = saveSource + ((args->source - LMBCS) - size_old);
+ args->sourceLimit = saveSourceLimit;
+
+ if (*err == U_TRUNCATED_CHAR_FOUND)
+ {
+ /* evil special case: source buffers so small a char spans more than 2 buffers */
+ args->converter->toULength = savebytes;
+ uprv_memcpy(args->converter->toUBytes, LMBCS, savebytes);
+ args->source = args->sourceLimit;
+ *err = U_ZERO_ERROR;
+ return;
+ }
+ else
+ {
+ /* clear the partial-char marker */
+ args->converter->toULength = 0;
+ }
+ }
+ else
+ {
+ errSource = saveSource;
+ uniChar = (UChar) _LMBCSGetNextUCharWorker(args, err);
+ savebytes = (int8_t)(args->source - saveSource);
+ }
+ if (U_SUCCESS(*err))
+ {
+ if (uniChar < 0xfffe)
+ {
+ *(args->target)++ = uniChar;
+ if(args->offsets)
+ {
+ *(args->offsets)++ = saveSource - pStartLMBCS;
+ }
+ }
+ else if (uniChar == 0xfffe)
+ {
+ *err = U_INVALID_CHAR_FOUND;
+ }
+ else /* if (uniChar == 0xffff) */
+ {
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+ }
+ }
+ /* if target ran out before source, return U_BUFFER_OVERFLOW_ERROR */
+ if (U_SUCCESS(*err) && args->sourceLimit > args->source && args->targetLimit <= args->target)
+ {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ else if (U_FAILURE(*err))
+ {
+ /* If character incomplete or unmappable/illegal, store it in toUBytes[] */
+ args->converter->toULength = savebytes;
+ if (savebytes > 0) {
+ uprv_memcpy(args->converter->toUBytes, errSource, savebytes);
+ }
+ if (*err == U_TRUNCATED_CHAR_FOUND) {
+ *err = U_ZERO_ERROR;
+ }
+ }
+}
+
+/* And now, the macroized declarations of data & functions: */
+DEFINE_LMBCS_OPEN(1)
+DEFINE_LMBCS_OPEN(2)
+DEFINE_LMBCS_OPEN(3)
+DEFINE_LMBCS_OPEN(4)
+DEFINE_LMBCS_OPEN(5)
+DEFINE_LMBCS_OPEN(6)
+DEFINE_LMBCS_OPEN(8)
+DEFINE_LMBCS_OPEN(11)
+DEFINE_LMBCS_OPEN(16)
+DEFINE_LMBCS_OPEN(17)
+DEFINE_LMBCS_OPEN(18)
+DEFINE_LMBCS_OPEN(19)
+
+
+DECLARE_LMBCS_DATA(1)
+DECLARE_LMBCS_DATA(2)
+DECLARE_LMBCS_DATA(3)
+DECLARE_LMBCS_DATA(4)
+DECLARE_LMBCS_DATA(5)
+DECLARE_LMBCS_DATA(6)
+DECLARE_LMBCS_DATA(8)
+DECLARE_LMBCS_DATA(11)
+DECLARE_LMBCS_DATA(16)
+DECLARE_LMBCS_DATA(17)
+DECLARE_LMBCS_DATA(18)
+DECLARE_LMBCS_DATA(19)
+
+#endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_set.c b/Build/source/libs/icu/icu-xetex/common/ucnv_set.c
new file mode 100644
index 00000000000..772e7ed8176
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_set.c
@@ -0,0 +1,67 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2003-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: ucnv_set.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004sep07
+* created by: Markus W. Scherer
+*
+* Conversion API functions using USet (ucnv_getUnicodeSet())
+* moved here from ucnv.c for removing the dependency of other ucnv_
+* implementation functions on the USet implementation.
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "unicode/ucnv.h"
+#include "ucnv_bld.h"
+#include "uset_imp.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+U_CAPI void U_EXPORT2
+ucnv_getUnicodeSet(const UConverter *cnv,
+ USet *setFillIn,
+ UConverterUnicodeSet whichSet,
+ UErrorCode *pErrorCode) {
+ /* argument checking */
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return;
+ }
+ if(cnv==NULL || setFillIn==NULL || whichSetsharedData->impl->getUnicodeSet==NULL) {
+ *pErrorCode=U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ {
+ USetAdder sa={
+ NULL,
+ uset_add,
+ uset_addRange,
+ uset_addString,
+ uset_remove
+ };
+ sa.set=setFillIn;
+
+ /* empty the set */
+ uset_clear(setFillIn);
+
+ /* call the converter to add the code points it supports */
+ cnv->sharedData->impl->getUnicodeSet(cnv, &sa, whichSet, pErrorCode);
+ }
+}
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_u16.c b/Build/source/libs/icu/icu-xetex/common/ucnv_u16.c
new file mode 100644
index 00000000000..6fc9e2a4493
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_u16.c
@@ -0,0 +1,1372 @@
+/*
+**********************************************************************
+* Copyright (C) 2002-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: ucnv_u16.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2002jul01
+* created by: Markus W. Scherer
+*
+* UTF-16 converter implementation. Used to be in ucnv_utf.c.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+#include "cmemory.h"
+
+enum {
+ UCNV_NEED_TO_WRITE_BOM=1
+};
+
+/* UTF-16BE ----------------------------------------------------------------- */
+
+#if U_IS_BIG_ENDIAN
+# define _UTF16PEFromUnicodeWithOffsets _UTF16BEFromUnicodeWithOffsets
+#else
+# define _UTF16PEFromUnicodeWithOffsets _UTF16LEFromUnicodeWithOffsets
+#endif
+
+
+static void
+_UTF16BEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const UChar *source;
+ char *target;
+ int32_t *offsets;
+
+ uint32_t targetCapacity, length, sourceIndex;
+ UChar c, trail;
+ char overflow[4];
+
+ source=pArgs->source;
+ length=(int32_t)(pArgs->sourceLimit-source);
+ if(length<=0) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ cnv=pArgs->converter;
+
+ /* write the BOM if necessary */
+ if(cnv->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ (char)0xfe, (char)0xff };
+ ucnv_fromUWriteBytes(cnv,
+ bom, 2,
+ &pArgs->target, pArgs->targetLimit,
+ &pArgs->offsets, -1,
+ pErrorCode);
+ cnv->fromUnicodeStatus=0;
+ }
+
+ target=pArgs->target;
+ if(target >= pArgs->targetLimit) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+
+ targetCapacity=(uint32_t)(pArgs->targetLimit-target);
+ offsets=pArgs->offsets;
+ sourceIndex=0;
+
+ /* c!=0 indicates in several places outside the main loops that a surrogate was found */
+
+ if((c=(UChar)cnv->fromUChar32)!=0 && U16_IS_TRAIL(trail=*source) && targetCapacity>=4) {
+ /* the last buffer ended with a lead surrogate, output the surrogate pair */
+ ++source;
+ --length;
+ target[0]=(uint8_t)(c>>8);
+ target[1]=(uint8_t)c;
+ target[2]=(uint8_t)(trail>>8);
+ target[3]=(uint8_t)trail;
+ target+=4;
+ targetCapacity-=4;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ *offsets++=-1;
+ *offsets++=-1;
+ *offsets++=-1;
+ }
+ sourceIndex=1;
+ cnv->fromUChar32=c=0;
+ }
+
+ if(c==0) {
+ /* copy an even number of bytes for complete UChars */
+ uint32_t count=2*length;
+ if(count>targetCapacity) {
+ count=targetCapacity&~1;
+ }
+ /* count is even */
+ targetCapacity-=count;
+ count>>=1;
+ length-=count;
+
+ if(offsets==NULL) {
+ while(count>0) {
+ c=*source++;
+ if(U16_IS_SINGLE(c)) {
+ target[0]=(uint8_t)(c>>8);
+ target[1]=(uint8_t)c;
+ target+=2;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 && U16_IS_TRAIL(trail=*source)) {
+ ++source;
+ --count;
+ target[0]=(uint8_t)(c>>8);
+ target[1]=(uint8_t)c;
+ target[2]=(uint8_t)(trail>>8);
+ target[3]=(uint8_t)trail;
+ target+=4;
+ } else {
+ break;
+ }
+ --count;
+ }
+ } else {
+ while(count>0) {
+ c=*source++;
+ if(U16_IS_SINGLE(c)) {
+ target[0]=(uint8_t)(c>>8);
+ target[1]=(uint8_t)c;
+ target+=2;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 && U16_IS_TRAIL(trail=*source)) {
+ ++source;
+ --count;
+ target[0]=(uint8_t)(c>>8);
+ target[1]=(uint8_t)c;
+ target[2]=(uint8_t)(trail>>8);
+ target[3]=(uint8_t)trail;
+ target+=4;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ sourceIndex+=2;
+ } else {
+ break;
+ }
+ --count;
+ }
+ }
+
+ if(count==0) {
+ /* done with the loop for complete UChars */
+ if(length>0 && targetCapacity>0) {
+ /*
+ * there is more input and some target capacity -
+ * it must be targetCapacity==1 because otherwise
+ * the above would have copied more;
+ * prepare for overflow output
+ */
+ if(U16_IS_SINGLE(c=*source++)) {
+ overflow[0]=(char)(c>>8);
+ overflow[1]=(char)c;
+ length=2; /* 2 bytes to output */
+ c=0;
+ /* } else { keep c for surrogate handling, length will be set there */
+ }
+ } else {
+ length=0;
+ c=0;
+ }
+ } else {
+ /* keep c for surrogate handling, length will be set there */
+ targetCapacity+=2*count;
+ }
+ } else {
+ length=0; /* from here on, length counts the bytes in overflow[] */
+ }
+
+ if(c!=0) {
+ /*
+ * c is a surrogate, and
+ * - source or target too short
+ * - or the surrogate is unmatched
+ */
+ length=0;
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(sourcesourceLimit) {
+ if(U16_IS_TRAIL(trail=*source)) {
+ /* output the surrogate pair, will overflow (see conditions comment above) */
+ ++source;
+ overflow[0]=(char)(c>>8);
+ overflow[1]=(char)c;
+ overflow[2]=(char)(trail>>8);
+ overflow[3]=(char)trail;
+ length=4; /* 4 bytes to output */
+ c=0;
+ } else {
+ /* unmatched lead surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* see if the trail surrogate is in the next buffer */
+ }
+ } else {
+ /* unmatched trail surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ cnv->fromUChar32=c;
+ }
+
+ if(length>0) {
+ /* output length bytes with overflow (length>targetCapacity>0) */
+ ucnv_fromUWriteBytes(cnv,
+ overflow, length,
+ (char **)&target, pArgs->targetLimit,
+ &offsets, sourceIndex,
+ pErrorCode);
+ targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target);
+ }
+
+ if(U_SUCCESS(*pErrorCode) && sourcesourceLimit && targetCapacity==0) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ /* write back the updated pointers */
+ pArgs->source=source;
+ pArgs->target=(char *)target;
+ pArgs->offsets=offsets;
+}
+
+static void
+_UTF16BEToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const uint8_t *source;
+ UChar *target;
+ int32_t *offsets;
+
+ uint32_t targetCapacity, length, count, sourceIndex;
+ UChar c, trail;
+
+ cnv=pArgs->converter;
+ source=(const uint8_t *)pArgs->source;
+ length=(int32_t)((const uint8_t *)pArgs->sourceLimit-source);
+ if(length<=0 && cnv->toUnicodeStatus==0) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ target=pArgs->target;
+ if(target >= pArgs->targetLimit) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+
+ targetCapacity=(uint32_t)(pArgs->targetLimit-target);
+ offsets=pArgs->offsets;
+ sourceIndex=0;
+ c=0;
+
+ /* complete a partial UChar or pair from the last call */
+ if(cnv->toUnicodeStatus!=0) {
+ /*
+ * special case: single byte from a previous buffer,
+ * where the byte turned out not to belong to a trail surrogate
+ * and the preceding, unmatched lead surrogate was put into toUBytes[]
+ * for error handling
+ */
+ cnv->toUBytes[0]=(uint8_t)cnv->toUnicodeStatus;
+ cnv->toULength=1;
+ cnv->toUnicodeStatus=0;
+ }
+ if((count=cnv->toULength)!=0) {
+ uint8_t *p=cnv->toUBytes;
+ do {
+ p[count++]=*source++;
+ ++sourceIndex;
+ --length;
+ if(count==2) {
+ c=((UChar)p[0]<<8)|p[1];
+ if(U16_IS_SINGLE(c)) {
+ /* output the BMP code point */
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ }
+ --targetCapacity;
+ count=0;
+ c=0;
+ break;
+ } else if(U16_IS_SURROGATE_LEAD(c)) {
+ /* continue collecting bytes for the trail surrogate */
+ c=0; /* avoid unnecessary surrogate handling below */
+ } else {
+ /* fall through to error handling for an unmatched trail surrogate */
+ break;
+ }
+ } else if(count==4) {
+ c=((UChar)p[0]<<8)|p[1];
+ trail=((UChar)p[2]<<8)|p[3];
+ if(U16_IS_TRAIL(trail)) {
+ /* output the surrogate pair */
+ *target++=c;
+ if(targetCapacity>=2) {
+ *target++=trail;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ *offsets++=-1;
+ }
+ targetCapacity-=2;
+ } else /* targetCapacity==1 */ {
+ targetCapacity=0;
+ cnv->UCharErrorBuffer[0]=trail;
+ cnv->UCharErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ count=0;
+ c=0;
+ break;
+ } else {
+ /* unmatched lead surrogate, handle here for consistent toUBytes[] */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+
+ /* back out reading the code unit after it */
+ if(((const uint8_t *)pArgs->source-source)>=2) {
+ source-=2;
+ } else {
+ /*
+ * if the trail unit's first byte was in a previous buffer, then
+ * we need to put it into a special place because toUBytes[] will be
+ * used for the lead unit's bytes
+ */
+ cnv->toUnicodeStatus=0x100|p[2];
+ --source;
+ }
+ cnv->toULength=2;
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+ return;
+ }
+ }
+ } while(length>0);
+ cnv->toULength=(int8_t)count;
+ }
+
+ /* copy an even number of bytes for complete UChars */
+ count=2*targetCapacity;
+ if(count>length) {
+ count=length&~1;
+ }
+ if(c==0 && count>0) {
+ length-=count;
+ count>>=1;
+ targetCapacity-=count;
+ if(offsets==NULL) {
+ do {
+ c=((UChar)source[0]<<8)|source[1];
+ source+=2;
+ if(U16_IS_SINGLE(c)) {
+ *target++=c;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 &&
+ U16_IS_TRAIL(trail=((UChar)source[0]<<8)|source[1])
+ ) {
+ source+=2;
+ --count;
+ *target++=c;
+ *target++=trail;
+ } else {
+ break;
+ }
+ } while(--count>0);
+ } else {
+ do {
+ c=((UChar)source[0]<<8)|source[1];
+ source+=2;
+ if(U16_IS_SINGLE(c)) {
+ *target++=c;
+ *offsets++=sourceIndex;
+ sourceIndex+=2;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 &&
+ U16_IS_TRAIL(trail=((UChar)source[0]<<8)|source[1])
+ ) {
+ source+=2;
+ --count;
+ *target++=c;
+ *target++=trail;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ sourceIndex+=4;
+ } else {
+ break;
+ }
+ } while(--count>0);
+ }
+
+ if(count==0) {
+ /* done with the loop for complete UChars */
+ c=0;
+ } else {
+ /* keep c for surrogate handling, trail will be set there */
+ length+=2*(count-1); /* one more byte pair was consumed than count decremented */
+ targetCapacity+=count;
+ }
+ }
+
+ if(c!=0) {
+ /*
+ * c is a surrogate, and
+ * - source or target too short
+ * - or the surrogate is unmatched
+ */
+ cnv->toUBytes[0]=(uint8_t)(c>>8);
+ cnv->toUBytes[1]=(uint8_t)c;
+ cnv->toULength=2;
+
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(length>=2) {
+ if(U16_IS_TRAIL(trail=((UChar)source[0]<<8)|source[1])) {
+ /* output the surrogate pair, will overflow (see conditions comment above) */
+ source+=2;
+ length-=2;
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ }
+ cnv->UCharErrorBuffer[0]=trail;
+ cnv->UCharErrorBufferLength=1;
+ cnv->toULength=0;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ } else {
+ /* unmatched lead surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* see if the trail surrogate is in the next buffer */
+ }
+ } else {
+ /* unmatched trail surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ }
+
+ if(U_SUCCESS(*pErrorCode)) {
+ /* check for a remaining source byte */
+ if(length>0) {
+ if(targetCapacity==0) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ } else {
+ /* it must be length==1 because otherwise the above would have copied more */
+ cnv->toUBytes[cnv->toULength++]=*source++;
+ }
+ }
+ }
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+}
+
+static UChar32
+_UTF16BEGetNextUChar(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
+ const uint8_t *s, *sourceLimit;
+ UChar32 c;
+
+ s=(const uint8_t *)pArgs->source;
+ sourceLimit=(const uint8_t *)pArgs->sourceLimit;
+
+ if(s>=sourceLimit) {
+ /* no input */
+ *err=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0xffff;
+ }
+
+ if(s+2>sourceLimit) {
+ /* only one byte: truncated UChar */
+ pArgs->converter->toUBytes[0]=*s++;
+ pArgs->converter->toULength=1;
+ pArgs->source=(const char *)s;
+ *err = U_TRUNCATED_CHAR_FOUND;
+ return 0xffff;
+ }
+
+ /* get one UChar */
+ c=((UChar32)*s<<8)|s[1];
+ s+=2;
+
+ /* check for a surrogate pair */
+ if(U_IS_SURROGATE(c)) {
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(s+2<=sourceLimit) {
+ UChar trail;
+
+ /* get a second UChar and see if it is a trail surrogate */
+ trail=((UChar)*s<<8)|s[1];
+ if(U16_IS_TRAIL(trail)) {
+ c=U16_GET_SUPPLEMENTARY(c, trail);
+ s+=2;
+ } else {
+ /* unmatched lead surrogate */
+ c=-2;
+ }
+ } else {
+ /* too few (2 or 3) bytes for a surrogate pair: truncated code point */
+ uint8_t *bytes=pArgs->converter->toUBytes;
+ s-=2;
+ pArgs->converter->toULength=(int8_t)(sourceLimit-s);
+ do {
+ *bytes++=*s++;
+ } while(sconverter->toUBytes;
+ pArgs->converter->toULength=2;
+ *bytes=*(s-2);
+ bytes[1]=*(s-1);
+
+ c=0xffff;
+ *err=U_ILLEGAL_CHAR_FOUND;
+ }
+ }
+
+ pArgs->source=(const char *)s;
+ return c;
+}
+
+static const UConverterImpl _UTF16BEImpl={
+ UCNV_UTF16_BigEndian,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+
+ _UTF16BEToUnicodeWithOffsets,
+ _UTF16BEToUnicodeWithOffsets,
+ _UTF16BEFromUnicodeWithOffsets,
+ _UTF16BEFromUnicodeWithOffsets,
+ _UTF16BEGetNextUChar,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+static const UConverterStaticData _UTF16BEStaticData={
+ sizeof(UConverterStaticData),
+ "UTF-16BE",
+ 1200, UCNV_IBM, UCNV_UTF16_BigEndian, 2, 2,
+ { 0xff, 0xfd, 0, 0 },2,FALSE,FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+
+const UConverterSharedData _UTF16BEData={
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF16BEStaticData, FALSE, &_UTF16BEImpl,
+ 0
+};
+
+/* UTF-16LE ----------------------------------------------------------------- */
+
+static void
+_UTF16LEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const UChar *source;
+ char *target;
+ int32_t *offsets;
+
+ uint32_t targetCapacity, length, sourceIndex;
+ UChar c, trail;
+ char overflow[4];
+
+ source=pArgs->source;
+ length=(int32_t)(pArgs->sourceLimit-source);
+ if(length<=0) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ cnv=pArgs->converter;
+
+ /* write the BOM if necessary */
+ if(cnv->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ (char)0xff, (char)0xfe };
+ ucnv_fromUWriteBytes(cnv,
+ bom, 2,
+ &pArgs->target, pArgs->targetLimit,
+ &pArgs->offsets, -1,
+ pErrorCode);
+ cnv->fromUnicodeStatus=0;
+ }
+
+ target=pArgs->target;
+ if(target >= pArgs->targetLimit) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+
+ targetCapacity=(uint32_t)(pArgs->targetLimit-pArgs->target);
+ offsets=pArgs->offsets;
+ sourceIndex=0;
+
+ /* c!=0 indicates in several places outside the main loops that a surrogate was found */
+
+ if((c=(UChar)cnv->fromUChar32)!=0 && U16_IS_TRAIL(trail=*source) && targetCapacity>=4) {
+ /* the last buffer ended with a lead surrogate, output the surrogate pair */
+ ++source;
+ --length;
+ target[0]=(uint8_t)c;
+ target[1]=(uint8_t)(c>>8);
+ target[2]=(uint8_t)trail;
+ target[3]=(uint8_t)(trail>>8);
+ target+=4;
+ targetCapacity-=4;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ *offsets++=-1;
+ *offsets++=-1;
+ *offsets++=-1;
+ }
+ sourceIndex=1;
+ cnv->fromUChar32=c=0;
+ }
+
+ if(c==0) {
+ /* copy an even number of bytes for complete UChars */
+ uint32_t count=2*length;
+ if(count>targetCapacity) {
+ count=targetCapacity&~1;
+ }
+ /* count is even */
+ targetCapacity-=count;
+ count>>=1;
+ length-=count;
+
+ if(offsets==NULL) {
+ while(count>0) {
+ c=*source++;
+ if(U16_IS_SINGLE(c)) {
+ target[0]=(uint8_t)c;
+ target[1]=(uint8_t)(c>>8);
+ target+=2;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 && U16_IS_TRAIL(trail=*source)) {
+ ++source;
+ --count;
+ target[0]=(uint8_t)c;
+ target[1]=(uint8_t)(c>>8);
+ target[2]=(uint8_t)trail;
+ target[3]=(uint8_t)(trail>>8);
+ target+=4;
+ } else {
+ break;
+ }
+ --count;
+ }
+ } else {
+ while(count>0) {
+ c=*source++;
+ if(U16_IS_SINGLE(c)) {
+ target[0]=(uint8_t)c;
+ target[1]=(uint8_t)(c>>8);
+ target+=2;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 && U16_IS_TRAIL(trail=*source)) {
+ ++source;
+ --count;
+ target[0]=(uint8_t)c;
+ target[1]=(uint8_t)(c>>8);
+ target[2]=(uint8_t)trail;
+ target[3]=(uint8_t)(trail>>8);
+ target+=4;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ sourceIndex+=2;
+ } else {
+ break;
+ }
+ --count;
+ }
+ }
+
+ if(count==0) {
+ /* done with the loop for complete UChars */
+ if(length>0 && targetCapacity>0) {
+ /*
+ * there is more input and some target capacity -
+ * it must be targetCapacity==1 because otherwise
+ * the above would have copied more;
+ * prepare for overflow output
+ */
+ if(U16_IS_SINGLE(c=*source++)) {
+ overflow[0]=(char)c;
+ overflow[1]=(char)(c>>8);
+ length=2; /* 2 bytes to output */
+ c=0;
+ /* } else { keep c for surrogate handling, length will be set there */
+ }
+ } else {
+ length=0;
+ c=0;
+ }
+ } else {
+ /* keep c for surrogate handling, length will be set there */
+ targetCapacity+=2*count;
+ }
+ } else {
+ length=0; /* from here on, length counts the bytes in overflow[] */
+ }
+
+ if(c!=0) {
+ /*
+ * c is a surrogate, and
+ * - source or target too short
+ * - or the surrogate is unmatched
+ */
+ length=0;
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(sourcesourceLimit) {
+ if(U16_IS_TRAIL(trail=*source)) {
+ /* output the surrogate pair, will overflow (see conditions comment above) */
+ ++source;
+ overflow[0]=(char)c;
+ overflow[1]=(char)(c>>8);
+ overflow[2]=(char)trail;
+ overflow[3]=(char)(trail>>8);
+ length=4; /* 4 bytes to output */
+ c=0;
+ } else {
+ /* unmatched lead surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* see if the trail surrogate is in the next buffer */
+ }
+ } else {
+ /* unmatched trail surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ cnv->fromUChar32=c;
+ }
+
+ if(length>0) {
+ /* output length bytes with overflow (length>targetCapacity>0) */
+ ucnv_fromUWriteBytes(cnv,
+ overflow, length,
+ &target, pArgs->targetLimit,
+ &offsets, sourceIndex,
+ pErrorCode);
+ targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target);
+ }
+
+ if(U_SUCCESS(*pErrorCode) && sourcesourceLimit && targetCapacity==0) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ /* write back the updated pointers */
+ pArgs->source=source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+}
+
+static void
+_UTF16LEToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const uint8_t *source;
+ UChar *target;
+ int32_t *offsets;
+
+ uint32_t targetCapacity, length, count, sourceIndex;
+ UChar c, trail;
+
+ cnv=pArgs->converter;
+ source=(const uint8_t *)pArgs->source;
+ length=(int32_t)((const uint8_t *)pArgs->sourceLimit-source);
+ if(length<=0 && cnv->toUnicodeStatus==0) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ target=pArgs->target;
+ if(target >= pArgs->targetLimit) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+
+ targetCapacity=(uint32_t)(pArgs->targetLimit-pArgs->target);
+ offsets=pArgs->offsets;
+ sourceIndex=0;
+ c=0;
+
+ /* complete a partial UChar or pair from the last call */
+ if(cnv->toUnicodeStatus!=0) {
+ /*
+ * special case: single byte from a previous buffer,
+ * where the byte turned out not to belong to a trail surrogate
+ * and the preceding, unmatched lead surrogate was put into toUBytes[]
+ * for error handling
+ */
+ cnv->toUBytes[0]=(uint8_t)cnv->toUnicodeStatus;
+ cnv->toULength=1;
+ cnv->toUnicodeStatus=0;
+ }
+ if((count=cnv->toULength)!=0) {
+ uint8_t *p=cnv->toUBytes;
+ do {
+ p[count++]=*source++;
+ ++sourceIndex;
+ --length;
+ if(count==2) {
+ c=((UChar)p[1]<<8)|p[0];
+ if(U16_IS_SINGLE(c)) {
+ /* output the BMP code point */
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ }
+ --targetCapacity;
+ count=0;
+ c=0;
+ break;
+ } else if(U16_IS_SURROGATE_LEAD(c)) {
+ /* continue collecting bytes for the trail surrogate */
+ c=0; /* avoid unnecessary surrogate handling below */
+ } else {
+ /* fall through to error handling for an unmatched trail surrogate */
+ break;
+ }
+ } else if(count==4) {
+ c=((UChar)p[1]<<8)|p[0];
+ trail=((UChar)p[3]<<8)|p[2];
+ if(U16_IS_TRAIL(trail)) {
+ /* output the surrogate pair */
+ *target++=c;
+ if(targetCapacity>=2) {
+ *target++=trail;
+ if(offsets!=NULL) {
+ *offsets++=-1;
+ *offsets++=-1;
+ }
+ targetCapacity-=2;
+ } else /* targetCapacity==1 */ {
+ targetCapacity=0;
+ cnv->UCharErrorBuffer[0]=trail;
+ cnv->UCharErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ count=0;
+ c=0;
+ break;
+ } else {
+ /* unmatched lead surrogate, handle here for consistent toUBytes[] */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+
+ /* back out reading the code unit after it */
+ if(((const uint8_t *)pArgs->source-source)>=2) {
+ source-=2;
+ } else {
+ /*
+ * if the trail unit's first byte was in a previous buffer, then
+ * we need to put it into a special place because toUBytes[] will be
+ * used for the lead unit's bytes
+ */
+ cnv->toUnicodeStatus=0x100|p[2];
+ --source;
+ }
+ cnv->toULength=2;
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+ return;
+ }
+ }
+ } while(length>0);
+ cnv->toULength=(int8_t)count;
+ }
+
+ /* copy an even number of bytes for complete UChars */
+ count=2*targetCapacity;
+ if(count>length) {
+ count=length&~1;
+ }
+ if(c==0 && count>0) {
+ length-=count;
+ count>>=1;
+ targetCapacity-=count;
+ if(offsets==NULL) {
+ do {
+ c=((UChar)source[1]<<8)|source[0];
+ source+=2;
+ if(U16_IS_SINGLE(c)) {
+ *target++=c;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 &&
+ U16_IS_TRAIL(trail=((UChar)source[1]<<8)|source[0])
+ ) {
+ source+=2;
+ --count;
+ *target++=c;
+ *target++=trail;
+ } else {
+ break;
+ }
+ } while(--count>0);
+ } else {
+ do {
+ c=((UChar)source[1]<<8)|source[0];
+ source+=2;
+ if(U16_IS_SINGLE(c)) {
+ *target++=c;
+ *offsets++=sourceIndex;
+ sourceIndex+=2;
+ } else if(U16_IS_SURROGATE_LEAD(c) && count>=2 &&
+ U16_IS_TRAIL(trail=((UChar)source[1]<<8)|source[0])
+ ) {
+ source+=2;
+ --count;
+ *target++=c;
+ *target++=trail;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ sourceIndex+=4;
+ } else {
+ break;
+ }
+ } while(--count>0);
+ }
+
+ if(count==0) {
+ /* done with the loop for complete UChars */
+ c=0;
+ } else {
+ /* keep c for surrogate handling, trail will be set there */
+ length+=2*(count-1); /* one more byte pair was consumed than count decremented */
+ targetCapacity+=count;
+ }
+ }
+
+ if(c!=0) {
+ /*
+ * c is a surrogate, and
+ * - source or target too short
+ * - or the surrogate is unmatched
+ */
+ cnv->toUBytes[0]=(uint8_t)c;
+ cnv->toUBytes[1]=(uint8_t)(c>>8);
+ cnv->toULength=2;
+
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(length>=2) {
+ if(U16_IS_TRAIL(trail=((UChar)source[1]<<8)|source[0])) {
+ /* output the surrogate pair, will overflow (see conditions comment above) */
+ source+=2;
+ length-=2;
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ }
+ cnv->UCharErrorBuffer[0]=trail;
+ cnv->UCharErrorBufferLength=1;
+ cnv->toULength=0;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ } else {
+ /* unmatched lead surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ } else {
+ /* see if the trail surrogate is in the next buffer */
+ }
+ } else {
+ /* unmatched trail surrogate */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ }
+ }
+
+ if(U_SUCCESS(*pErrorCode)) {
+ /* check for a remaining source byte */
+ if(length>0) {
+ if(targetCapacity==0) {
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ } else {
+ /* it must be length==1 because otherwise the above would have copied more */
+ cnv->toUBytes[cnv->toULength++]=*source++;
+ }
+ }
+ }
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+}
+
+static UChar32
+_UTF16LEGetNextUChar(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
+ const uint8_t *s, *sourceLimit;
+ UChar32 c;
+
+ s=(const uint8_t *)pArgs->source;
+ sourceLimit=(const uint8_t *)pArgs->sourceLimit;
+
+ if(s>=sourceLimit) {
+ /* no input */
+ *err=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0xffff;
+ }
+
+ if(s+2>sourceLimit) {
+ /* only one byte: truncated UChar */
+ pArgs->converter->toUBytes[0]=*s++;
+ pArgs->converter->toULength=1;
+ pArgs->source=(const char *)s;
+ *err = U_TRUNCATED_CHAR_FOUND;
+ return 0xffff;
+ }
+
+ /* get one UChar */
+ c=((UChar32)s[1]<<8)|*s;
+ s+=2;
+
+ /* check for a surrogate pair */
+ if(U_IS_SURROGATE(c)) {
+ if(U16_IS_SURROGATE_LEAD(c)) {
+ if(s+2<=sourceLimit) {
+ UChar trail;
+
+ /* get a second UChar and see if it is a trail surrogate */
+ trail=((UChar)s[1]<<8)|*s;
+ if(U16_IS_TRAIL(trail)) {
+ c=U16_GET_SUPPLEMENTARY(c, trail);
+ s+=2;
+ } else {
+ /* unmatched lead surrogate */
+ c=-2;
+ }
+ } else {
+ /* too few (2 or 3) bytes for a surrogate pair: truncated code point */
+ uint8_t *bytes=pArgs->converter->toUBytes;
+ s-=2;
+ pArgs->converter->toULength=(int8_t)(sourceLimit-s);
+ do {
+ *bytes++=*s++;
+ } while(sconverter->toUBytes;
+ pArgs->converter->toULength=2;
+ *bytes=*(s-2);
+ bytes[1]=*(s-1);
+
+ c=0xffff;
+ *err=U_ILLEGAL_CHAR_FOUND;
+ }
+ }
+
+ pArgs->source=(const char *)s;
+ return c;
+}
+
+static const UConverterImpl _UTF16LEImpl={
+ UCNV_UTF16_LittleEndian,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+
+ _UTF16LEToUnicodeWithOffsets,
+ _UTF16LEToUnicodeWithOffsets,
+ _UTF16LEFromUnicodeWithOffsets,
+ _UTF16LEFromUnicodeWithOffsets,
+ _UTF16LEGetNextUChar,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+
+static const UConverterStaticData _UTF16LEStaticData={
+ sizeof(UConverterStaticData),
+ "UTF-16LE",
+ 1202, UCNV_IBM, UCNV_UTF16_LittleEndian, 2, 2,
+ { 0xfd, 0xff, 0, 0 },2,FALSE,FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+
+const UConverterSharedData _UTF16LEData={
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF16LEStaticData, FALSE, &_UTF16LEImpl,
+ 0
+};
+
+/* UTF-16 (Detect BOM) ------------------------------------------------------ */
+
+/*
+ * Detect a BOM at the beginning of the stream and select UTF-16BE or UTF-16LE
+ * accordingly.
+ * This is a simpler version of the UTF-32 converter below, with
+ * fewer states for shorter BOMs.
+ *
+ * State values:
+ * 0 initial state
+ * 1 saw FE
+ * 2..4 -
+ * 5 saw FF
+ * 6..7 -
+ * 8 UTF-16BE mode
+ * 9 UTF-16LE mode
+ *
+ * During detection: state&3==number of matching bytes so far.
+ *
+ * On output, emit U+FEFF as the first code point.
+ */
+
+static void
+_UTF16Reset(UConverter *cnv, UConverterResetChoice choice) {
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ /* reset toUnicode: state=0 */
+ cnv->mode=0;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ /* reset fromUnicode: prepare to output the UTF-16PE BOM */
+ cnv->fromUnicodeStatus=UCNV_NEED_TO_WRITE_BOM;
+ }
+}
+
+static void
+_UTF16Open(UConverter *cnv,
+ const char *name,
+ const char *locale,
+ uint32_t options,
+ UErrorCode *pErrorCode) {
+ _UTF16Reset(cnv, UCNV_RESET_BOTH);
+}
+
+static const char utf16BOM[8]={ (char)0xfe, (char)0xff, 0, 0, (char)0xff, (char)0xfe, 0, 0 };
+
+static void
+_UTF16ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv=pArgs->converter;
+ const char *source=pArgs->source;
+ const char *sourceLimit=pArgs->sourceLimit;
+ int32_t *offsets=pArgs->offsets;
+
+ int32_t state, offsetDelta;
+ char b;
+
+ state=cnv->mode;
+
+ /*
+ * If we detect a BOM in this buffer, then we must add the BOM size to the
+ * offsets because the actual converter function will not see and count the BOM.
+ * offsetDelta will have the number of the BOM bytes that are in the current buffer.
+ */
+ offsetDelta=0;
+
+ while(sourcesource);
+ } else if(state==5) {
+ state=9; /* detect UTF-16LE */
+ offsetDelta=(int32_t)(source-pArgs->source);
+ }
+ } else {
+ /* switch to UTF-16BE and pass the previous bytes */
+ if(source!=pArgs->source) {
+ /* just reset the source */
+ source=pArgs->source;
+ } else {
+ UBool oldFlush=pArgs->flush;
+
+ /* the first byte is from a previous buffer, replay it first */
+ pArgs->source=utf16BOM+(state&4); /* select the correct BOM */
+ pArgs->sourceLimit=pArgs->source+1; /* replay previous byte */
+ pArgs->flush=FALSE; /* this sourceLimit is not the real source stream limit */
+
+ _UTF16BEToUnicodeWithOffsets(pArgs, pErrorCode);
+
+ /* restore real pointers; pArgs->source will be set in case 8/9 */
+ pArgs->sourceLimit=sourceLimit;
+ pArgs->flush=oldFlush;
+ }
+ state=8;
+ continue;
+ }
+ break;
+ case 8:
+ /* call UTF-16BE */
+ pArgs->source=source;
+ _UTF16BEToUnicodeWithOffsets(pArgs, pErrorCode);
+ source=pArgs->source;
+ break;
+ case 9:
+ /* call UTF-16LE */
+ pArgs->source=source;
+ _UTF16LEToUnicodeWithOffsets(pArgs, pErrorCode);
+ source=pArgs->source;
+ break;
+ default:
+ break; /* does not occur */
+ }
+ }
+
+ /* add BOM size to offsets - see comment at offsetDelta declaration */
+ if(offsets!=NULL && offsetDelta!=0) {
+ int32_t *offsetsLimit=pArgs->offsets;
+ while(offsetssource=source;
+
+ if(source==sourceLimit && pArgs->flush) {
+ /* handle truncated input */
+ switch(state) {
+ case 0:
+ break; /* no input at all, nothing to do */
+ case 8:
+ _UTF16BEToUnicodeWithOffsets(pArgs, pErrorCode);
+ break;
+ case 9:
+ _UTF16LEToUnicodeWithOffsets(pArgs, pErrorCode);
+ break;
+ default:
+ /* handle 0source=utf16BOM+(state&4); /* select the correct BOM */
+ pArgs->sourceLimit=pArgs->source+(state&3); /* replay bytes */
+
+ /* no offsets: not enough for output */
+ _UTF16BEToUnicodeWithOffsets(pArgs, pErrorCode);
+ pArgs->source=source;
+ pArgs->sourceLimit=sourceLimit;
+ state=8;
+ break;
+ }
+ }
+
+ cnv->mode=state;
+}
+
+static UChar32
+_UTF16GetNextUChar(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ switch(pArgs->converter->mode) {
+ case 8:
+ return _UTF16BEGetNextUChar(pArgs, pErrorCode);
+ case 9:
+ return _UTF16LEGetNextUChar(pArgs, pErrorCode);
+ default:
+ return UCNV_GET_NEXT_UCHAR_USE_TO_U;
+ }
+}
+
+static const UConverterImpl _UTF16Impl = {
+ UCNV_UTF16,
+
+ NULL,
+ NULL,
+
+ _UTF16Open,
+ NULL,
+ _UTF16Reset,
+
+ _UTF16ToUnicodeWithOffsets,
+ _UTF16ToUnicodeWithOffsets,
+ _UTF16PEFromUnicodeWithOffsets,
+ _UTF16PEFromUnicodeWithOffsets,
+ _UTF16GetNextUChar,
+
+ NULL, /* ### TODO implement getStarters for all Unicode encodings?! */
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+static const UConverterStaticData _UTF16StaticData = {
+ sizeof(UConverterStaticData),
+ "UTF-16",
+ 1204, /* CCSID for BOM sensitive UTF-16 */
+ UCNV_IBM, UCNV_UTF16, 2, 2,
+#if U_IS_BIG_ENDIAN
+ { 0xff, 0xfd, 0, 0 }, 2,
+#else
+ { 0xfd, 0xff, 0, 0 }, 2,
+#endif
+ FALSE, FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+const UConverterSharedData _UTF16Data = {
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF16StaticData, FALSE, &_UTF16Impl,
+ 0
+};
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_u32.c b/Build/source/libs/icu/icu-xetex/common/ucnv_u32.c
new file mode 100644
index 00000000000..034bf9bbcb9
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_u32.c
@@ -0,0 +1,1250 @@
+/*
+**********************************************************************
+* Copyright (C) 2002-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: ucnv_u32.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2002jul01
+* created by: Markus W. Scherer
+*
+* UTF-32 converter implementation. Used to be in ucnv_utf.c.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+#include "cmemory.h"
+
+#define MAXIMUM_UCS2 0x0000FFFF
+#define MAXIMUM_UTF 0x0010FFFF
+#define HALF_SHIFT 10
+#define HALF_BASE 0x0010000
+#define HALF_MASK 0x3FF
+#define SURROGATE_HIGH_START 0xD800
+#define SURROGATE_LOW_START 0xDC00
+
+/* -SURROGATE_LOW_START + HALF_BASE */
+#define SURROGATE_LOW_BASE 9216
+
+enum {
+ UCNV_NEED_TO_WRITE_BOM=1
+};
+
+/* UTF-32BE ----------------------------------------------------------------- */
+
+static void
+T_UConverter_toUnicode_UTF32_BE(UConverterToUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const unsigned char *mySource = (unsigned char *) args->source;
+ UChar *myTarget = args->target;
+ const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
+ const UChar *targetLimit = args->targetLimit;
+ unsigned char *toUBytes = args->converter->toUBytes;
+ uint32_t ch, i;
+
+ /* Restore state of current sequence */
+ if (args->converter->toUnicodeStatus && myTarget < targetLimit) {
+ i = args->converter->toULength; /* restore # of bytes consumed */
+ args->converter->toULength = 0;
+
+ ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
+ args->converter->toUnicodeStatus = 0;
+ goto morebytes;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit) {
+ i = 0;
+ ch = 0;
+morebytes:
+ while (i < sizeof(uint32_t)) {
+ if (mySource < sourceLimit) {
+ ch = (ch << 8) | (uint8_t)(*mySource);
+ toUBytes[i++] = (char) *(mySource++);
+ }
+ else {
+ /* stores a partially calculated target*/
+ /* + 1 to make 0 a valid character */
+ args->converter->toUnicodeStatus = ch + 1;
+ args->converter->toULength = (int8_t) i;
+ goto donefornow;
+ }
+ }
+
+ if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
+ /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
+ if (ch <= MAXIMUM_UCS2)
+ {
+ /* fits in 16 bits */
+ *(myTarget++) = (UChar) ch;
+ }
+ else {
+ /* write out the surrogates */
+ *(myTarget++) = U16_LEAD(ch);
+ ch = U16_TRAIL(ch);
+ if (myTarget < targetLimit) {
+ *(myTarget++) = (UChar)ch;
+ }
+ else {
+ /* Put in overflow buffer (not handled here) */
+ args->converter->UCharErrorBuffer[0] = (UChar) ch;
+ args->converter->UCharErrorBufferLength = 1;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+ else {
+ args->converter->toULength = (int8_t)i;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+donefornow:
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
+ /* End of target buffer */
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = myTarget;
+ args->source = (const char *) mySource;
+}
+
+static void
+T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC(UConverterToUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const unsigned char *mySource = (unsigned char *) args->source;
+ UChar *myTarget = args->target;
+ int32_t *myOffsets = args->offsets;
+ const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
+ const UChar *targetLimit = args->targetLimit;
+ unsigned char *toUBytes = args->converter->toUBytes;
+ uint32_t ch, i;
+ int32_t offsetNum = 0;
+
+ /* Restore state of current sequence */
+ if (args->converter->toUnicodeStatus && myTarget < targetLimit) {
+ i = args->converter->toULength; /* restore # of bytes consumed */
+ args->converter->toULength = 0;
+
+ ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
+ args->converter->toUnicodeStatus = 0;
+ goto morebytes;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit) {
+ i = 0;
+ ch = 0;
+morebytes:
+ while (i < sizeof(uint32_t)) {
+ if (mySource < sourceLimit) {
+ ch = (ch << 8) | (uint8_t)(*mySource);
+ toUBytes[i++] = (char) *(mySource++);
+ }
+ else {
+ /* stores a partially calculated target*/
+ /* + 1 to make 0 a valid character */
+ args->converter->toUnicodeStatus = ch + 1;
+ args->converter->toULength = (int8_t) i;
+ goto donefornow;
+ }
+ }
+
+ if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
+ /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
+ if (ch <= MAXIMUM_UCS2) {
+ /* fits in 16 bits */
+ *(myTarget++) = (UChar) ch;
+ *(myOffsets++) = offsetNum;
+ }
+ else {
+ /* write out the surrogates */
+ *(myTarget++) = U16_LEAD(ch);
+ *myOffsets++ = offsetNum;
+ ch = U16_TRAIL(ch);
+ if (myTarget < targetLimit)
+ {
+ *(myTarget++) = (UChar)ch;
+ *(myOffsets++) = offsetNum;
+ }
+ else {
+ /* Put in overflow buffer (not handled here) */
+ args->converter->UCharErrorBuffer[0] = (UChar) ch;
+ args->converter->UCharErrorBufferLength = 1;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+ else {
+ args->converter->toULength = (int8_t)i;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ offsetNum += i;
+ }
+
+donefornow:
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
+ {
+ /* End of target buffer */
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = myTarget;
+ args->source = (const char *) mySource;
+ args->offsets = myOffsets;
+}
+
+static void
+T_UConverter_fromUnicode_UTF32_BE(UConverterFromUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const UChar *mySource = args->source;
+ unsigned char *myTarget;
+ const UChar *sourceLimit = args->sourceLimit;
+ const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
+ UChar32 ch, ch2;
+ unsigned int indexToWrite;
+ unsigned char temp[sizeof(uint32_t)];
+
+ if(mySource >= sourceLimit) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ /* write the BOM if necessary */
+ if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ 0, 0, (char)0xfe, (char)0xff };
+ ucnv_fromUWriteBytes(args->converter,
+ bom, 4,
+ &args->target, args->targetLimit,
+ &args->offsets, -1,
+ err);
+ args->converter->fromUnicodeStatus=0;
+ }
+
+ myTarget = (unsigned char *) args->target;
+ temp[0] = 0;
+
+ if (args->converter->fromUChar32) {
+ ch = args->converter->fromUChar32;
+ args->converter->fromUChar32 = 0;
+ goto lowsurogate;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit) {
+ ch = *(mySource++);
+
+ if (UTF_IS_SURROGATE(ch)) {
+ if (U_IS_LEAD(ch)) {
+lowsurogate:
+ if (mySource < sourceLimit) {
+ ch2 = *mySource;
+ if (U_IS_TRAIL(ch2)) {
+ ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
+ mySource++;
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ else {
+ /* ran out of source */
+ args->converter->fromUChar32 = ch;
+ if (args->flush) {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+ break;
+ }
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+ /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
+ temp[1] = (uint8_t) (ch >> 16 & 0x1F);
+ temp[2] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
+ temp[3] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
+
+ for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++) {
+ if (myTarget < targetLimit) {
+ *(myTarget++) = temp[indexToWrite];
+ }
+ else {
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ }
+
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = (char *) myTarget;
+ args->source = mySource;
+}
+
+static void
+T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC(UConverterFromUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const UChar *mySource = args->source;
+ unsigned char *myTarget;
+ int32_t *myOffsets;
+ const UChar *sourceLimit = args->sourceLimit;
+ const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
+ UChar32 ch, ch2;
+ int32_t offsetNum = 0;
+ unsigned int indexToWrite;
+ unsigned char temp[sizeof(uint32_t)];
+
+ if(mySource >= sourceLimit) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ /* write the BOM if necessary */
+ if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ 0, 0, (char)0xfe, (char)0xff };
+ ucnv_fromUWriteBytes(args->converter,
+ bom, 4,
+ &args->target, args->targetLimit,
+ &args->offsets, -1,
+ err);
+ args->converter->fromUnicodeStatus=0;
+ }
+
+ myTarget = (unsigned char *) args->target;
+ myOffsets = args->offsets;
+ temp[0] = 0;
+
+ if (args->converter->fromUChar32) {
+ ch = args->converter->fromUChar32;
+ args->converter->fromUChar32 = 0;
+ goto lowsurogate;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit) {
+ ch = *(mySource++);
+
+ if (UTF_IS_SURROGATE(ch)) {
+ if (U_IS_LEAD(ch)) {
+lowsurogate:
+ if (mySource < sourceLimit) {
+ ch2 = *mySource;
+ if (U_IS_TRAIL(ch2)) {
+ ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
+ mySource++;
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ else {
+ /* ran out of source */
+ args->converter->fromUChar32 = ch;
+ if (args->flush) {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+ break;
+ }
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+ /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
+ temp[1] = (uint8_t) (ch >> 16 & 0x1F);
+ temp[2] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
+ temp[3] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
+
+ for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++) {
+ if (myTarget < targetLimit) {
+ *(myTarget++) = temp[indexToWrite];
+ *(myOffsets++) = offsetNum;
+ }
+ else {
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ offsetNum = offsetNum + 1 + (temp[1] != 0);
+ }
+
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = (char *) myTarget;
+ args->source = mySource;
+ args->offsets = myOffsets;
+}
+
+static UChar32
+T_UConverter_getNextUChar_UTF32_BE(UConverterToUnicodeArgs* args,
+ UErrorCode* err)
+{
+ const uint8_t *mySource;
+ UChar32 myUChar;
+ int32_t length;
+
+ mySource = (const uint8_t *)args->source;
+ if (mySource >= (const uint8_t *)args->sourceLimit)
+ {
+ /* no input */
+ *err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0xffff;
+ }
+
+ length = (int32_t)((const uint8_t *)args->sourceLimit - mySource);
+ if (length < 4)
+ {
+ /* got a partial character */
+ uprv_memcpy(args->converter->toUBytes, mySource, length);
+ args->converter->toULength = (int8_t)length;
+ args->source = (const char *)(mySource + length);
+ *err = U_TRUNCATED_CHAR_FOUND;
+ return 0xffff;
+ }
+
+ /* Don't even try to do a direct cast because the value may be on an odd address. */
+ myUChar = ((UChar32)mySource[0] << 24)
+ | ((UChar32)mySource[1] << 16)
+ | ((UChar32)mySource[2] << 8)
+ | ((UChar32)mySource[3]);
+
+ args->source = (const char *)(mySource + 4);
+ if ((uint32_t)myUChar <= MAXIMUM_UTF && !U_IS_SURROGATE(myUChar)) {
+ return myUChar;
+ }
+
+ uprv_memcpy(args->converter->toUBytes, mySource, 4);
+ args->converter->toULength = 4;
+
+ *err = U_ILLEGAL_CHAR_FOUND;
+ return 0xffff;
+}
+
+static const UConverterImpl _UTF32BEImpl = {
+ UCNV_UTF32_BigEndian,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+
+ T_UConverter_toUnicode_UTF32_BE,
+ T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC,
+ T_UConverter_fromUnicode_UTF32_BE,
+ T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC,
+ T_UConverter_getNextUChar_UTF32_BE,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+/* The 1232 CCSID refers to any version of Unicode with any endianess of UTF-32 */
+static const UConverterStaticData _UTF32BEStaticData = {
+ sizeof(UConverterStaticData),
+ "UTF-32BE",
+ 1232,
+ UCNV_IBM, UCNV_UTF32_BigEndian, 4, 4,
+ { 0, 0, 0xff, 0xfd }, 4, FALSE, FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+const UConverterSharedData _UTF32BEData = {
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF32BEStaticData, FALSE, &_UTF32BEImpl,
+ 0
+};
+
+/* UTF-32LE ---------------------------------------------------------- */
+
+static void
+T_UConverter_toUnicode_UTF32_LE(UConverterToUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const unsigned char *mySource = (unsigned char *) args->source;
+ UChar *myTarget = args->target;
+ const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
+ const UChar *targetLimit = args->targetLimit;
+ unsigned char *toUBytes = args->converter->toUBytes;
+ uint32_t ch, i;
+
+ /* Restore state of current sequence */
+ if (args->converter->toUnicodeStatus && myTarget < targetLimit)
+ {
+ i = args->converter->toULength; /* restore # of bytes consumed */
+ args->converter->toULength = 0;
+
+ /* Stores the previously calculated ch from a previous call*/
+ ch = args->converter->toUnicodeStatus - 1;
+ args->converter->toUnicodeStatus = 0;
+ goto morebytes;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit)
+ {
+ i = 0;
+ ch = 0;
+morebytes:
+ while (i < sizeof(uint32_t))
+ {
+ if (mySource < sourceLimit)
+ {
+ ch |= ((uint8_t)(*mySource)) << (i * 8);
+ toUBytes[i++] = (char) *(mySource++);
+ }
+ else
+ {
+ /* stores a partially calculated target*/
+ /* + 1 to make 0 a valid character */
+ args->converter->toUnicodeStatus = ch + 1;
+ args->converter->toULength = (int8_t) i;
+ goto donefornow;
+ }
+ }
+
+ if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
+ /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
+ if (ch <= MAXIMUM_UCS2) {
+ /* fits in 16 bits */
+ *(myTarget++) = (UChar) ch;
+ }
+ else {
+ /* write out the surrogates */
+ *(myTarget++) = U16_LEAD(ch);
+ ch = U16_TRAIL(ch);
+ if (myTarget < targetLimit) {
+ *(myTarget++) = (UChar)ch;
+ }
+ else {
+ /* Put in overflow buffer (not handled here) */
+ args->converter->UCharErrorBuffer[0] = (UChar) ch;
+ args->converter->UCharErrorBufferLength = 1;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+ else {
+ args->converter->toULength = (int8_t)i;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+donefornow:
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
+ {
+ /* End of target buffer */
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = myTarget;
+ args->source = (const char *) mySource;
+}
+
+static void
+T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC(UConverterToUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const unsigned char *mySource = (unsigned char *) args->source;
+ UChar *myTarget = args->target;
+ int32_t *myOffsets = args->offsets;
+ const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
+ const UChar *targetLimit = args->targetLimit;
+ unsigned char *toUBytes = args->converter->toUBytes;
+ uint32_t ch, i;
+ int32_t offsetNum = 0;
+
+ /* Restore state of current sequence */
+ if (args->converter->toUnicodeStatus && myTarget < targetLimit)
+ {
+ i = args->converter->toULength; /* restore # of bytes consumed */
+ args->converter->toULength = 0;
+
+ /* Stores the previously calculated ch from a previous call*/
+ ch = args->converter->toUnicodeStatus - 1;
+ args->converter->toUnicodeStatus = 0;
+ goto morebytes;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit)
+ {
+ i = 0;
+ ch = 0;
+morebytes:
+ while (i < sizeof(uint32_t))
+ {
+ if (mySource < sourceLimit)
+ {
+ ch |= ((uint8_t)(*mySource)) << (i * 8);
+ toUBytes[i++] = (char) *(mySource++);
+ }
+ else
+ {
+ /* stores a partially calculated target*/
+ /* + 1 to make 0 a valid character */
+ args->converter->toUnicodeStatus = ch + 1;
+ args->converter->toULength = (int8_t) i;
+ goto donefornow;
+ }
+ }
+
+ if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch))
+ {
+ /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
+ if (ch <= MAXIMUM_UCS2)
+ {
+ /* fits in 16 bits */
+ *(myTarget++) = (UChar) ch;
+ *(myOffsets++) = offsetNum;
+ }
+ else {
+ /* write out the surrogates */
+ *(myTarget++) = U16_LEAD(ch);
+ *(myOffsets++) = offsetNum;
+ ch = U16_TRAIL(ch);
+ if (myTarget < targetLimit)
+ {
+ *(myTarget++) = (UChar)ch;
+ *(myOffsets++) = offsetNum;
+ }
+ else
+ {
+ /* Put in overflow buffer (not handled here) */
+ args->converter->UCharErrorBuffer[0] = (UChar) ch;
+ args->converter->UCharErrorBufferLength = 1;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+ else
+ {
+ args->converter->toULength = (int8_t)i;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ offsetNum += i;
+ }
+
+donefornow:
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
+ {
+ /* End of target buffer */
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = myTarget;
+ args->source = (const char *) mySource;
+ args->offsets = myOffsets;
+}
+
+static void
+T_UConverter_fromUnicode_UTF32_LE(UConverterFromUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const UChar *mySource = args->source;
+ unsigned char *myTarget;
+ const UChar *sourceLimit = args->sourceLimit;
+ const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
+ UChar32 ch, ch2;
+ unsigned int indexToWrite;
+ unsigned char temp[sizeof(uint32_t)];
+
+ if(mySource >= sourceLimit) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ /* write the BOM if necessary */
+ if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ (char)0xff, (char)0xfe, 0, 0 };
+ ucnv_fromUWriteBytes(args->converter,
+ bom, 4,
+ &args->target, args->targetLimit,
+ &args->offsets, -1,
+ err);
+ args->converter->fromUnicodeStatus=0;
+ }
+
+ myTarget = (unsigned char *) args->target;
+ temp[3] = 0;
+
+ if (args->converter->fromUChar32)
+ {
+ ch = args->converter->fromUChar32;
+ args->converter->fromUChar32 = 0;
+ goto lowsurogate;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit)
+ {
+ ch = *(mySource++);
+
+ if (UTF_IS_SURROGATE(ch)) {
+ if (U_IS_LEAD(ch))
+ {
+lowsurogate:
+ if (mySource < sourceLimit)
+ {
+ ch2 = *mySource;
+ if (U_IS_TRAIL(ch2)) {
+ ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
+ mySource++;
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ else {
+ /* ran out of source */
+ args->converter->fromUChar32 = ch;
+ if (args->flush) {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+ break;
+ }
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+ /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
+ temp[2] = (uint8_t) (ch >> 16 & 0x1F);
+ temp[1] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
+ temp[0] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
+
+ for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++)
+ {
+ if (myTarget < targetLimit)
+ {
+ *(myTarget++) = temp[indexToWrite];
+ }
+ else
+ {
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ }
+
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
+ {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = (char *) myTarget;
+ args->source = mySource;
+}
+
+static void
+T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC(UConverterFromUnicodeArgs * args,
+ UErrorCode * err)
+{
+ const UChar *mySource = args->source;
+ unsigned char *myTarget;
+ int32_t *myOffsets;
+ const UChar *sourceLimit = args->sourceLimit;
+ const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
+ UChar32 ch, ch2;
+ unsigned int indexToWrite;
+ unsigned char temp[sizeof(uint32_t)];
+ int32_t offsetNum = 0;
+
+ if(mySource >= sourceLimit) {
+ /* no input, nothing to do */
+ return;
+ }
+
+ /* write the BOM if necessary */
+ if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
+ static const char bom[]={ (char)0xff, (char)0xfe, 0, 0 };
+ ucnv_fromUWriteBytes(args->converter,
+ bom, 4,
+ &args->target, args->targetLimit,
+ &args->offsets, -1,
+ err);
+ args->converter->fromUnicodeStatus=0;
+ }
+
+ myTarget = (unsigned char *) args->target;
+ myOffsets = args->offsets;
+ temp[3] = 0;
+
+ if (args->converter->fromUChar32)
+ {
+ ch = args->converter->fromUChar32;
+ args->converter->fromUChar32 = 0;
+ goto lowsurogate;
+ }
+
+ while (mySource < sourceLimit && myTarget < targetLimit)
+ {
+ ch = *(mySource++);
+
+ if (UTF_IS_SURROGATE(ch)) {
+ if (U_IS_LEAD(ch))
+ {
+lowsurogate:
+ if (mySource < sourceLimit)
+ {
+ ch2 = *mySource;
+ if (U_IS_TRAIL(ch2))
+ {
+ ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
+ mySource++;
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ else {
+ /* ran out of source */
+ args->converter->fromUChar32 = ch;
+ if (args->flush) {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ *err = U_ILLEGAL_CHAR_FOUND;
+ }
+ break;
+ }
+ }
+ else {
+ /* this is an unmatched trail code unit (2nd surrogate) */
+ /* callback(illegal) */
+ args->converter->fromUChar32 = ch;
+ *err = U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+
+ /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
+ temp[2] = (uint8_t) (ch >> 16 & 0x1F);
+ temp[1] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
+ temp[0] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
+
+ for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++)
+ {
+ if (myTarget < targetLimit)
+ {
+ *(myTarget++) = temp[indexToWrite];
+ *(myOffsets++) = offsetNum;
+ }
+ else
+ {
+ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ offsetNum = offsetNum + 1 + (temp[2] != 0);
+ }
+
+ if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
+ {
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ args->target = (char *) myTarget;
+ args->source = mySource;
+ args->offsets = myOffsets;
+}
+
+static UChar32
+T_UConverter_getNextUChar_UTF32_LE(UConverterToUnicodeArgs* args,
+ UErrorCode* err)
+{
+ const uint8_t *mySource;
+ UChar32 myUChar;
+ int32_t length;
+
+ mySource = (const uint8_t *)args->source;
+ if (mySource >= (const uint8_t *)args->sourceLimit)
+ {
+ /* no input */
+ *err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0xffff;
+ }
+
+ length = (int32_t)((const uint8_t *)args->sourceLimit - mySource);
+ if (length < 4)
+ {
+ /* got a partial character */
+ uprv_memcpy(args->converter->toUBytes, mySource, length);
+ args->converter->toULength = (int8_t)length;
+ args->source = (const char *)(mySource + length);
+ *err = U_TRUNCATED_CHAR_FOUND;
+ return 0xffff;
+ }
+
+ /* Don't even try to do a direct cast because the value may be on an odd address. */
+ myUChar = ((UChar32)mySource[3] << 24)
+ | ((UChar32)mySource[2] << 16)
+ | ((UChar32)mySource[1] << 8)
+ | ((UChar32)mySource[0]);
+
+ args->source = (const char *)(mySource + 4);
+ if ((uint32_t)myUChar <= MAXIMUM_UTF && !U_IS_SURROGATE(myUChar)) {
+ return myUChar;
+ }
+
+ uprv_memcpy(args->converter->toUBytes, mySource, 4);
+ args->converter->toULength = 4;
+
+ *err = U_ILLEGAL_CHAR_FOUND;
+ return 0xffff;
+}
+
+static const UConverterImpl _UTF32LEImpl = {
+ UCNV_UTF32_LittleEndian,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+
+ T_UConverter_toUnicode_UTF32_LE,
+ T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC,
+ T_UConverter_fromUnicode_UTF32_LE,
+ T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC,
+ T_UConverter_getNextUChar_UTF32_LE,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+/* The 1232 CCSID refers to any version of Unicode with any endianess of UTF-32 */
+static const UConverterStaticData _UTF32LEStaticData = {
+ sizeof(UConverterStaticData),
+ "UTF-32LE",
+ 1234,
+ UCNV_IBM, UCNV_UTF32_LittleEndian, 4, 4,
+ { 0xfd, 0xff, 0, 0 }, 4, FALSE, FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+
+const UConverterSharedData _UTF32LEData = {
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF32LEStaticData, FALSE, &_UTF32LEImpl,
+ 0
+};
+
+/* UTF-32 (Detect BOM) ------------------------------------------------------ */
+
+/*
+ * Detect a BOM at the beginning of the stream and select UTF-32BE or UTF-32LE
+ * accordingly.
+ *
+ * State values:
+ * 0 initial state
+ * 1 saw 00
+ * 2 saw 00 00
+ * 3 saw 00 00 FE
+ * 4 -
+ * 5 saw FF
+ * 6 saw FF FE
+ * 7 saw FF FE 00
+ * 8 UTF-32BE mode
+ * 9 UTF-32LE mode
+ *
+ * During detection: state&3==number of matching bytes so far.
+ *
+ * On output, emit U+FEFF as the first code point.
+ */
+
+static void
+_UTF32Reset(UConverter *cnv, UConverterResetChoice choice) {
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ /* reset toUnicode: state=0 */
+ cnv->mode=0;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ /* reset fromUnicode: prepare to output the UTF-32PE BOM */
+ cnv->fromUnicodeStatus=UCNV_NEED_TO_WRITE_BOM;
+ }
+}
+
+static void
+_UTF32Open(UConverter *cnv,
+ const char *name,
+ const char *locale,
+ uint32_t options,
+ UErrorCode *pErrorCode) {
+ _UTF32Reset(cnv, UCNV_RESET_BOTH);
+}
+
+static const char utf32BOM[8]={ 0, 0, (char)0xfe, (char)0xff, (char)0xff, (char)0xfe, 0, 0 };
+
+static void
+_UTF32ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv=pArgs->converter;
+ const char *source=pArgs->source;
+ const char *sourceLimit=pArgs->sourceLimit;
+ int32_t *offsets=pArgs->offsets;
+
+ int32_t state, offsetDelta;
+ char b;
+
+ state=cnv->mode;
+
+ /*
+ * If we detect a BOM in this buffer, then we must add the BOM size to the
+ * offsets because the actual converter function will not see and count the BOM.
+ * offsetDelta will have the number of the BOM bytes that are in the current buffer.
+ */
+ offsetDelta=0;
+
+ while(sourcesource);
+ } else if(state==8) {
+ state=9; /* detect UTF-32LE */
+ offsetDelta=(int32_t)(source-pArgs->source);
+ }
+ } else {
+ /* switch to UTF-32BE and pass the previous bytes */
+ int32_t count=(int32_t)(source-pArgs->source); /* number of bytes from this buffer */
+
+ /* reset the source */
+ source=pArgs->source;
+
+ if(count==(state&3)) {
+ /* simple: all in the same buffer, just reset source */
+ } else {
+ UBool oldFlush=pArgs->flush;
+
+ /* some of the bytes are from a previous buffer, replay those first */
+ pArgs->source=utf32BOM+(state&4); /* select the correct BOM */
+ pArgs->sourceLimit=pArgs->source+((state&3)-count); /* replay previous bytes */
+ pArgs->flush=FALSE; /* this sourceLimit is not the real source stream limit */
+
+ /* no offsets: bytes from previous buffer, and not enough for output */
+ T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
+
+ /* restore real pointers; pArgs->source will be set in case 8/9 */
+ pArgs->sourceLimit=sourceLimit;
+ pArgs->flush=oldFlush;
+ }
+ state=8;
+ continue;
+ }
+ break;
+ case 8:
+ /* call UTF-32BE */
+ pArgs->source=source;
+ if(offsets==NULL) {
+ T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
+ } else {
+ T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC(pArgs, pErrorCode);
+ }
+ source=pArgs->source;
+ break;
+ case 9:
+ /* call UTF-32LE */
+ pArgs->source=source;
+ if(offsets==NULL) {
+ T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode);
+ } else {
+ T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC(pArgs, pErrorCode);
+ }
+ source=pArgs->source;
+ break;
+ default:
+ break; /* does not occur */
+ }
+ }
+
+ /* add BOM size to offsets - see comment at offsetDelta declaration */
+ if(offsets!=NULL && offsetDelta!=0) {
+ int32_t *offsetsLimit=pArgs->offsets;
+ while(offsetssource=source;
+
+ if(source==sourceLimit && pArgs->flush) {
+ /* handle truncated input */
+ switch(state) {
+ case 0:
+ break; /* no input at all, nothing to do */
+ case 8:
+ T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
+ break;
+ case 9:
+ T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode);
+ break;
+ default:
+ /* handle 0source=utf32BOM+(state&4); /* select the correct BOM */
+ pArgs->sourceLimit=pArgs->source+(state&3); /* replay bytes */
+
+ /* no offsets: not enough for output */
+ T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
+ pArgs->source=source;
+ pArgs->sourceLimit=sourceLimit;
+ state=8;
+ break;
+ }
+ }
+
+ cnv->mode=state;
+}
+
+static UChar32
+_UTF32GetNextUChar(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ switch(pArgs->converter->mode) {
+ case 8:
+ return T_UConverter_getNextUChar_UTF32_BE(pArgs, pErrorCode);
+ case 9:
+ return T_UConverter_getNextUChar_UTF32_LE(pArgs, pErrorCode);
+ default:
+ return UCNV_GET_NEXT_UCHAR_USE_TO_U;
+ }
+}
+
+static const UConverterImpl _UTF32Impl = {
+ UCNV_UTF32,
+
+ NULL,
+ NULL,
+
+ _UTF32Open,
+ NULL,
+ _UTF32Reset,
+
+ _UTF32ToUnicodeWithOffsets,
+ _UTF32ToUnicodeWithOffsets,
+#if U_IS_BIG_ENDIAN
+ T_UConverter_fromUnicode_UTF32_BE,
+ T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC,
+#else
+ T_UConverter_fromUnicode_UTF32_LE,
+ T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC,
+#endif
+ _UTF32GetNextUChar,
+
+ NULL, /* ### TODO implement getStarters for all Unicode encodings?! */
+ NULL,
+ NULL,
+ NULL,
+ ucnv_getNonSurrogateUnicodeSet
+};
+
+/* The 1236 CCSID refers to any version of Unicode with a BOM sensitive endianess of UTF-32 */
+static const UConverterStaticData _UTF32StaticData = {
+ sizeof(UConverterStaticData),
+ "UTF-32",
+ 1236,
+ UCNV_IBM, UCNV_UTF32, 4, 4,
+#if U_IS_BIG_ENDIAN
+ { 0, 0, 0xff, 0xfd }, 4,
+#else
+ { 0xfd, 0xff, 0, 0 }, 4,
+#endif
+ FALSE, FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+const UConverterSharedData _UTF32Data = {
+ sizeof(UConverterSharedData), ~((uint32_t) 0),
+ NULL, NULL, &_UTF32StaticData, FALSE, &_UTF32Impl,
+ 0
+};
+
+#endif
diff --git a/Build/source/libs/icu/icu-xetex/common/ucnv_u7.c b/Build/source/libs/icu/icu-xetex/common/ucnv_u7.c
new file mode 100644
index 00000000000..62e2792922c
--- /dev/null
+++ b/Build/source/libs/icu/icu-xetex/common/ucnv_u7.c
@@ -0,0 +1,1459 @@
+/*
+**********************************************************************
+* Copyright (C) 2002-2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: ucnv_u7.c
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2002jul01
+* created by: Markus W. Scherer
+*
+* UTF-7 converter implementation. Used to be in ucnv_utf.c.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucnv.h"
+#include "ucnv_bld.h"
+#include "ucnv_cnv.h"
+
+/* UTF-7 -------------------------------------------------------------------- */
+
+/*
+ * UTF-7 is a stateful encoding of Unicode.
+ * It is defined in RFC 2152. (http://www.ietf.org/rfc/rfc2152.txt)
+ * It was intended for use in Internet email systems, using in its bytewise
+ * encoding only a subset of 7-bit US-ASCII.
+ * UTF-7 is deprecated in favor of UTF-8/16/32 and SCSU, but still
+ * occasionally used.
+ *
+ * For converting Unicode to UTF-7, the RFC allows to encode some US-ASCII
+ * characters directly or in base64. Especially, the characters in set O
+ * as defined in the RFC (see below) may be encoded directly but are not
+ * allowed in, e.g., email headers.
+ * By default, the ICU UTF-7 converter encodes set O directly.
+ * By choosing the option "version=1", set O will be escaped instead.
+ * For example:
+ * utf7Converter=ucnv_open("UTF-7,version=1");
+ *
+ * For details about email headers see RFC 2047.
+ */
+
+/*
+ * Tests for US-ASCII characters belonging to character classes
+ * defined in UTF-7.
+ *
+ * Set D (directly encoded characters) consists of the following
+ * characters: the upper and lower case letters A through Z
+ * and a through z, the 10 digits 0-9, and the following nine special
+ * characters (note that "+" and "=" are omitted):
+ * '(),-./:?
+ *
+ * Set O (optional direct characters) consists of the following
+ * characters (note that "\" and "~" are omitted):
+ * !"#$%&*;<=>@[]^_`{|}
+ *
+ * According to the rules in RFC 2152, the byte values for the following
+ * US-ASCII characters are not used in UTF-7 and are therefore illegal:
+ * - all C0 control codes except for CR LF TAB
+ * - BACKSLASH
+ * - TILDE
+ * - DEL
+ * - all codes beyond US-ASCII, i.e. all >127
+ */
+#define inSetD(c) \
+ ((uint8_t)((c)-97)<26 || (uint8_t)((c)-65)<26 || /* letters */ \
+ (uint8_t)((c)-48)<10 || /* digits */ \
+ (uint8_t)((c)-39)<3 || /* '() */ \
+ (uint8_t)((c)-44)<4 || /* ,-./ */ \
+ (c)==58 || (c)==63 /* :? */ \
+ )
+
+#define inSetO(c) \
+ ((uint8_t)((c)-33)<6 || /* !"#$%& */ \
+ (uint8_t)((c)-59)<4 || /* ;<=> */ \
+ (uint8_t)((c)-93)<4 || /* ]^_` */ \
+ (uint8_t)((c)-123)<3 || /* {|} */ \
+ (c)==42 || (c)==64 || (c)==91 /* *@[ */ \
+ )
+
+#define isCRLFTAB(c) ((c)==13 || (c)==10 || (c)==9)
+#define isCRLFSPTAB(c) ((c)==32 || (c)==13 || (c)==10 || (c)==9)
+
+#define PLUS 43
+#define MINUS 45
+#define BACKSLASH 92
+#define TILDE 126
+
+/* legal byte values: all US-ASCII graphic characters from space to before tilde, and CR LF TAB */
+#define isLegalUTF7(c) (((uint8_t)((c)-32)<94 && (c)!=BACKSLASH) || isCRLFTAB(c))
+
+/* encode directly sets D and O and CR LF SP TAB */
+static const UBool encodeDirectlyMaximum[128]={
+ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
+};
+
+/* encode directly set D and CR LF SP TAB but not set O */
+static const UBool encodeDirectlyRestricted[128]={
+ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
+
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
+};
+
+static const uint8_t
+toBase64[64]={
+ /* A-Z */
+ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
+ /* a-z */
+ 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
+ 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
+ /* 0-9 */
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
+ /* +/ */
+ 43, 47
+};
+
+static const int8_t
+fromBase64[128]={
+ /* C0 controls, -1 for legal ones (CR LF TAB), -3 for illegal ones */
+ -3, -3, -3, -3, -3, -3, -3, -3, -3, -1, -1, -3, -3, -1, -3, -3,
+ -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
+
+ /* general punctuation with + and / and a special value (-2) for - */
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -2, -1, 63,
+ /* digits */
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
+
+ /* A-Z */
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -3, -1, -1, -1,
+
+ /* a-z */
+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -3, -3
+};
+
+/*
+ * converter status values:
+ *
+ * toUnicodeStatus:
+ * 24 inDirectMode (boolean)
+ * 23..16 base64Counter (-1..7)
+ * 15..0 bits (up to 14 bits incoming base64)
+ *
+ * fromUnicodeStatus:
+ * 31..28 version (0: set O direct 1: set O escaped)
+ * 24 inDirectMode (boolean)
+ * 23..16 base64Counter (0..2)
+ * 7..0 bits (6 bits outgoing base64)
+ *
+ */
+
+static void
+_UTF7Reset(UConverter *cnv, UConverterResetChoice choice) {
+ if(choice<=UCNV_RESET_TO_UNICODE) {
+ /* reset toUnicode */
+ cnv->toUnicodeStatus=0x1000000; /* inDirectMode=TRUE */
+ cnv->toULength=0;
+ }
+ if(choice!=UCNV_RESET_TO_UNICODE) {
+ /* reset fromUnicode */
+ cnv->fromUnicodeStatus=(cnv->fromUnicodeStatus&0xf0000000)|0x1000000; /* keep version, inDirectMode=TRUE */
+ }
+}
+
+static void
+_UTF7Open(UConverter *cnv,
+ const char *name,
+ const char *locale,
+ uint32_t options,
+ UErrorCode *pErrorCode) {
+ if((options&0xf)<=1) {
+ cnv->fromUnicodeStatus=(options&0xf)<<28;
+ _UTF7Reset(cnv, UCNV_RESET_BOTH);
+ } else {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+static void
+_UTF7ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const uint8_t *source, *sourceLimit;
+ UChar *target;
+ const UChar *targetLimit;
+ int32_t *offsets;
+
+ uint8_t *bytes;
+ uint8_t byteIndex;
+
+ int32_t length, targetCapacity;
+
+ /* UTF-7 state */
+ uint16_t bits;
+ int8_t base64Counter;
+ UBool inDirectMode;
+
+ int8_t base64Value;
+
+ int32_t sourceIndex, nextSourceIndex;
+
+ uint8_t b;
+ /* set up the local pointers */
+ cnv=pArgs->converter;
+
+ source=(const uint8_t *)pArgs->source;
+ sourceLimit=(const uint8_t *)pArgs->sourceLimit;
+ target=pArgs->target;
+ targetLimit=pArgs->targetLimit;
+ offsets=pArgs->offsets;
+ /* get the state machine state */
+ {
+ uint32_t status=cnv->toUnicodeStatus;
+ inDirectMode=(UBool)((status>>24)&1);
+ base64Counter=(int8_t)(status>>16);
+ bits=(uint16_t)status;
+ }
+ bytes=cnv->toUBytes;
+ byteIndex=cnv->toULength;
+
+ /* sourceIndex=-1 if the current character began in the previous buffer */
+ sourceIndex=byteIndex==0 ? 0 : -1;
+ nextSourceIndex=0;
+
+ if(inDirectMode) {
+directMode:
+ /*
+ * In Direct Mode, most US-ASCII characters are encoded directly, i.e.,
+ * with their US-ASCII byte values.
+ * Backslash and Tilde and most control characters are not allowed in UTF-7.
+ * A plus sign starts Unicode (or "escape") Mode.
+ *
+ * In Direct Mode, only the sourceIndex is used.
+ */
+ byteIndex=0;
+ length=(int32_t)(sourceLimit-source);
+ targetCapacity=(int32_t)(targetLimit-target);
+ if(length>targetCapacity) {
+ length=targetCapacity;
+ }
+ while(length>0) {
+ b=*source++;
+ if(!isLegalUTF7(b)) {
+ /* illegal */
+ bytes[0]=b;
+ byteIndex=1;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ } else if(b!=PLUS) {
+ /* write directly encoded character */
+ *target++=b;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ } else /* PLUS */ {
+ /* switch to Unicode mode */
+ nextSourceIndex=++sourceIndex;
+ inDirectMode=FALSE;
+ byteIndex=0;
+ bits=0;
+ base64Counter=-1;
+ goto unicodeMode;
+ }
+ --length;
+ }
+ if(source=targetLimit) {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+unicodeMode:
+ /*
+ * In Unicode (or "escape") Mode, UTF-16BE is base64-encoded.
+ * The base64 sequence ends with any character that is not in the base64 alphabet.
+ * A terminating minus sign is consumed.
+ *
+ * In Unicode Mode, the sourceIndex has the index to the start of the current
+ * base64 bytes, while nextSourceIndex is precisely parallel to source,
+ * keeping the index to the following byte.
+ * Note that in 2 out of 3 cases, UChars overlap within a base64 byte.
+ */
+ while(source=126) {
+ /* illegal - test other illegal US-ASCII values by base64Value==-3 */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ } else if((base64Value=fromBase64[b])>=0) {
+ /* collect base64 bytes into UChars */
+ switch(base64Counter) {
+ case -1: /* -1 is immediately after the + */
+ case 0:
+ bits=base64Value;
+ base64Counter=1;
+ break;
+ case 1:
+ case 3:
+ case 4:
+ case 6:
+ bits=(uint16_t)((bits<<6)|base64Value);
+ ++base64Counter;
+ break;
+ case 2:
+ *target++=(UChar)((bits<<4)|(base64Value>>2));
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex-1;
+ }
+ bytes[0]=b; /* keep this byte in case an error occurs */
+ byteIndex=1;
+ bits=(uint16_t)(base64Value&3);
+ base64Counter=3;
+ break;
+ case 5:
+ *target++=(UChar)((bits<<2)|(base64Value>>4));
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex-1;
+ }
+ bytes[0]=b; /* keep this byte in case an error occurs */
+ byteIndex=1;
+ bits=(uint16_t)(base64Value&15);
+ base64Counter=6;
+ break;
+ case 7:
+ *target++=(UChar)((bits<<6)|base64Value);
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex;
+ }
+ byteIndex=0;
+ bits=0;
+ base64Counter=0;
+ break;
+ default:
+ /* will never occur */
+ break;
+ }
+ } else if(base64Value==-2) {
+ /* minus sign terminates the base64 sequence */
+ inDirectMode=TRUE;
+ if(base64Counter==-1) {
+ /* +- i.e. a minus immediately following a plus */
+ *target++=PLUS;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex-1;
+ }
+ } else {
+ /* absorb the minus and leave the Unicode Mode */
+ if(bits!=0) {
+ /* bits are illegally left over, a UChar is incomplete */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ sourceIndex=nextSourceIndex;
+ goto directMode;
+ } else if(base64Value==-1) /* for any legal character except base64 and minus sign */ {
+ /* leave the Unicode Mode */
+ inDirectMode=TRUE;
+ if(base64Counter==-1) {
+ /* illegal: + immediately followed by something other than base64 or minus sign */
+ /* include the plus sign in the reported sequence */
+ --sourceIndex;
+ bytes[0]=PLUS;
+ bytes[1]=b;
+ byteIndex=2;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ } else if(bits==0) {
+ /* un-read the character in case it is a plus sign */
+ --source;
+ sourceIndex=nextSourceIndex-1;
+ goto directMode;
+ } else {
+ /* bits are illegally left over, a UChar is incomplete */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ } else /* base64Value==-3 for illegal characters */ {
+ /* illegal */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ } else {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+
+ if(U_SUCCESS(*pErrorCode) && pArgs->flush && source==sourceLimit && bits==0) {
+ /*
+ * if we are in Unicode mode, then the byteIndex might not be 0,
+ * but that is ok if bits==0
+ * -> we set byteIndex=0 at the end of the stream to avoid a truncated error
+ * (not true for IMAP-mailbox-name where we must end in direct mode)
+ */
+ byteIndex=0;
+ }
+
+ /* set the converter state back into UConverter */
+ cnv->toUnicodeStatus=((uint32_t)inDirectMode<<24)|((uint32_t)((uint8_t)base64Counter)<<16)|(uint32_t)bits;
+ cnv->toULength=byteIndex;
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+ return;
+}
+
+static void
+_UTF7FromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const UChar *source, *sourceLimit;
+ uint8_t *target, *targetLimit;
+ int32_t *offsets;
+
+ int32_t length, targetCapacity, sourceIndex;
+ UChar c;
+
+ /* UTF-7 state */
+ const UBool *encodeDirectly;
+ uint8_t bits;
+ int8_t base64Counter;
+ UBool inDirectMode;
+
+ /* set up the local pointers */
+ cnv=pArgs->converter;
+
+ /* set up the local pointers */
+ source=pArgs->source;
+ sourceLimit=pArgs->sourceLimit;
+ target=(uint8_t *)pArgs->target;
+ targetLimit=(uint8_t *)pArgs->targetLimit;
+ offsets=pArgs->offsets;
+
+ /* get the state machine state */
+ {
+ uint32_t status=cnv->fromUnicodeStatus;
+ encodeDirectly= status<0x10000000 ? encodeDirectlyMaximum : encodeDirectlyRestricted;
+ inDirectMode=(UBool)((status>>24)&1);
+ base64Counter=(int8_t)(status>>16);
+ bits=(uint8_t)status;
+ }
+
+ /* UTF-7 always encodes UTF-16 code units, therefore we need only a simple sourceIndex */
+ sourceIndex=0;
+
+ if(inDirectMode) {
+directMode:
+ length=(int32_t)(sourceLimit-source);
+ targetCapacity=(int32_t)(targetLimit-target);
+ if(length>targetCapacity) {
+ length=targetCapacity;
+ }
+ while(length>0) {
+ c=*source++;
+ /* currently always encode CR LF SP TAB directly */
+ if(c<=127 && encodeDirectly[c]) {
+ /* encode directly */
+ *target++=(uint8_t)c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ } else if(c==PLUS) {
+ /* output +- for + */
+ *target++=PLUS;
+ if(targetcharErrorBuffer[0]=MINUS;
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ } else {
+ /* un-read this character and switch to Unicode Mode */
+ --source;
+ *target++=PLUS;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ }
+ inDirectMode=FALSE;
+ base64Counter=0;
+ goto unicodeMode;
+ }
+ --length;
+ }
+ if(source=targetLimit) {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+unicodeMode:
+ while(sourcecharErrorBuffer[0]=MINUS;
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ goto directMode;
+ } else {
+ /*
+ * base64 this character:
+ * Output 2 or 3 base64 bytes for the remaining bits of the previous character
+ * and the bits of this character, each implicitly in UTF-16BE.
+ *
+ * Here, bits is an 8-bit variable because only 6 bits need to be kept from one
+ * character to the next. The actual 2 or 4 bits are shifted to the left edge
+ * of the 6-bits field 5..0 to make the termination of the base64 sequence easier.
+ */
+ switch(base64Counter) {
+ case 0:
+ *target++=toBase64[c>>10];
+ if(target>4)&0x3f];
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ cnv->charErrorBuffer[0]=toBase64[(c>>4)&0x3f];
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=(uint8_t)((c&15)<<2);
+ base64Counter=1;
+ break;
+ case 1:
+ *target++=toBase64[bits|(c>>14)];
+ if(target>8)&0x3f];
+ if(target>2)&0x3f];
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ cnv->charErrorBuffer[0]=toBase64[(c>>2)&0x3f];
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ cnv->charErrorBuffer[0]=toBase64[(c>>8)&0x3f];
+ cnv->charErrorBuffer[1]=toBase64[(c>>2)&0x3f];
+ cnv->charErrorBufferLength=2;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=(uint8_t)((c&3)<<4);
+ base64Counter=2;
+ break;
+ case 2:
+ *target++=toBase64[bits|(c>>12)];
+ if(target>6)&0x3f];
+ if(targetcharErrorBuffer[0]=toBase64[c&0x3f];
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ cnv->charErrorBuffer[0]=toBase64[(c>>6)&0x3f];
+ cnv->charErrorBuffer[1]=toBase64[c&0x3f];
+ cnv->charErrorBufferLength=2;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=0;
+ base64Counter=0;
+ break;
+ default:
+ /* will never occur */
+ break;
+ }
+ }
+ } else {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+
+ if(pArgs->flush && source>=sourceLimit) {
+ /* flush remaining bits to the target */
+ if(!inDirectMode && base64Counter!=0) {
+ if(targetcharErrorBuffer[cnv->charErrorBufferLength++]=toBase64[bits];
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ /* reset the state for the next conversion */
+ cnv->fromUnicodeStatus=(cnv->fromUnicodeStatus&0xf0000000)|0x1000000; /* keep version, inDirectMode=TRUE */
+ } else {
+ /* set the converter state back into UConverter */
+ cnv->fromUnicodeStatus=
+ (cnv->fromUnicodeStatus&0xf0000000)| /* keep version*/
+ ((uint32_t)inDirectMode<<24)|((uint32_t)base64Counter<<16)|(uint32_t)bits;
+ }
+
+ /* write back the updated pointers */
+ pArgs->source=source;
+ pArgs->target=(char *)target;
+ pArgs->offsets=offsets;
+ return;
+}
+
+static const char *
+_UTF7GetName(const UConverter *cnv) {
+ switch(cnv->fromUnicodeStatus>>28) {
+ case 1:
+ return "UTF-7,version=1";
+ default:
+ return "UTF-7";
+ }
+}
+
+static const UConverterImpl _UTF7Impl={
+ UCNV_UTF7,
+
+ NULL,
+ NULL,
+
+ _UTF7Open,
+ NULL,
+ _UTF7Reset,
+
+ _UTF7ToUnicodeWithOffsets,
+ _UTF7ToUnicodeWithOffsets,
+ _UTF7FromUnicodeWithOffsets,
+ _UTF7FromUnicodeWithOffsets,
+ NULL,
+
+ NULL,
+ _UTF7GetName,
+ NULL, /* we don't need writeSub() because we never call a callback at fromUnicode() */
+ NULL,
+ ucnv_getCompleteUnicodeSet
+};
+
+static const UConverterStaticData _UTF7StaticData={
+ sizeof(UConverterStaticData),
+ "UTF-7",
+ 0, /* TODO CCSID for UTF-7 */
+ UCNV_IBM, UCNV_UTF7,
+ 1, 4,
+ { 0x3f, 0, 0, 0 }, 1, /* the subchar is not used */
+ FALSE, FALSE,
+ 0,
+ 0,
+ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
+};
+
+const UConverterSharedData _UTF7Data={
+ sizeof(UConverterSharedData), ~((uint32_t)0),
+ NULL, NULL, &_UTF7StaticData, FALSE, &_UTF7Impl,
+ 0
+};
+
+/* IMAP mailbox name encoding ----------------------------------------------- */
+
+/*
+ * RFC 2060: INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1
+ * http://www.ietf.org/rfc/rfc2060.txt
+ *
+ * 5.1.3. Mailbox International Naming Convention
+ *
+ * By convention, international mailbox names are specified using a
+ * modified version of the UTF-7 encoding described in [UTF-7]. The
+ * purpose of these modifications is to correct the following problems
+ * with UTF-7:
+ *
+ * 1) UTF-7 uses the "+" character for shifting; this conflicts with
+ * the common use of "+" in mailbox names, in particular USENET
+ * newsgroup names.
+ *
+ * 2) UTF-7's encoding is BASE64 which uses the "/" character; this
+ * conflicts with the use of "/" as a popular hierarchy delimiter.
+ *
+ * 3) UTF-7 prohibits the unencoded usage of "\"; this conflicts with
+ * the use of "\" as a popular hierarchy delimiter.
+ *
+ * 4) UTF-7 prohibits the unencoded usage of "~"; this conflicts with
+ * the use of "~" in some servers as a home directory indicator.
+ *
+ * 5) UTF-7 permits multiple alternate forms to represent the same
+ * string; in particular, printable US-ASCII chararacters can be
+ * represented in encoded form.
+ *
+ * In modified UTF-7, printable US-ASCII characters except for "&"
+ * represent themselves; that is, characters with octet values 0x20-0x25
+ * and 0x27-0x7e. The character "&" (0x26) is represented by the two-
+ * octet sequence "&-".
+ *
+ * All other characters (octet values 0x00-0x1f, 0x7f-0xff, and all
+ * Unicode 16-bit octets) are represented in modified BASE64, with a
+ * further modification from [UTF-7] that "," is used instead of "/".
+ * Modified BASE64 MUST NOT be used to represent any printing US-ASCII
+ * character which can represent itself.
+ *
+ * "&" is used to shift to modified BASE64 and "-" to shift back to US-
+ * ASCII. All names start in US-ASCII, and MUST end in US-ASCII (that
+ * is, a name that ends with a Unicode 16-bit octet MUST end with a "-
+ * ").
+ *
+ * For example, here is a mailbox name which mixes English, Japanese,
+ * and Chinese text: ~peter/mail/&ZeVnLIqe-/&U,BTFw-
+ */
+
+/*
+ * Tests for US-ASCII characters belonging to character classes
+ * defined in UTF-7.
+ *
+ * Set D (directly encoded characters) consists of the following
+ * characters: the upper and lower case letters A through Z
+ * and a through z, the 10 digits 0-9, and the following nine special
+ * characters (note that "+" and "=" are omitted):
+ * '(),-./:?
+ *
+ * Set O (optional direct characters) consists of the following
+ * characters (note that "\" and "~" are omitted):
+ * !"#$%&*;<=>@[]^_`{|}
+ *
+ * According to the rules in RFC 2152, the byte values for the following
+ * US-ASCII characters are not used in UTF-7 and are therefore illegal:
+ * - all C0 control codes except for CR LF TAB
+ * - BACKSLASH
+ * - TILDE
+ * - DEL
+ * - all codes beyond US-ASCII, i.e. all >127
+ */
+
+/* uses '&' not '+' to start a base64 sequence */
+#define AMPERSAND 0x26
+#define COMMA 0x2c
+#define SLASH 0x2f
+
+/* legal byte values: all US-ASCII graphic characters 0x20..0x7e */
+#define isLegalIMAP(c) (0x20<=(c) && (c)<=0x7e)
+
+/* direct-encode all of printable ASCII 0x20..0x7e except '&' 0x26 */
+#define inSetDIMAP(c) (isLegalIMAP(c) && c!=AMPERSAND)
+
+#define TO_BASE64_IMAP(n) ((n)<63 ? toBase64[n] : COMMA)
+#define FROM_BASE64_IMAP(c) ((c)==COMMA ? 63 : (c)==SLASH ? -1 : fromBase64[c])
+
+/*
+ * converter status values:
+ *
+ * toUnicodeStatus:
+ * 24 inDirectMode (boolean)
+ * 23..16 base64Counter (-1..7)
+ * 15..0 bits (up to 14 bits incoming base64)
+ *
+ * fromUnicodeStatus:
+ * 24 inDirectMode (boolean)
+ * 23..16 base64Counter (0..2)
+ * 7..0 bits (6 bits outgoing base64)
+ *
+ * ignore bits 31..25
+ */
+
+static void
+_IMAPToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const uint8_t *source, *sourceLimit;
+ UChar *target;
+ const UChar *targetLimit;
+ int32_t *offsets;
+
+ uint8_t *bytes;
+ uint8_t byteIndex;
+
+ int32_t length, targetCapacity;
+
+ /* UTF-7 state */
+ uint16_t bits;
+ int8_t base64Counter;
+ UBool inDirectMode;
+
+ int8_t base64Value;
+
+ int32_t sourceIndex, nextSourceIndex;
+
+ UChar c;
+ uint8_t b;
+
+ /* set up the local pointers */
+ cnv=pArgs->converter;
+
+ source=(const uint8_t *)pArgs->source;
+ sourceLimit=(const uint8_t *)pArgs->sourceLimit;
+ target=pArgs->target;
+ targetLimit=pArgs->targetLimit;
+ offsets=pArgs->offsets;
+ /* get the state machine state */
+ {
+ uint32_t status=cnv->toUnicodeStatus;
+ inDirectMode=(UBool)((status>>24)&1);
+ base64Counter=(int8_t)(status>>16);
+ bits=(uint16_t)status;
+ }
+ bytes=cnv->toUBytes;
+ byteIndex=cnv->toULength;
+
+ /* sourceIndex=-1 if the current character began in the previous buffer */
+ sourceIndex=byteIndex==0 ? 0 : -1;
+ nextSourceIndex=0;
+
+ if(inDirectMode) {
+directMode:
+ /*
+ * In Direct Mode, US-ASCII characters are encoded directly, i.e.,
+ * with their US-ASCII byte values.
+ * An ampersand starts Unicode (or "escape") Mode.
+ *
+ * In Direct Mode, only the sourceIndex is used.
+ */
+ byteIndex=0;
+ length=(int32_t)(sourceLimit-source);
+ targetCapacity=(int32_t)(targetLimit-target);
+ if(length>targetCapacity) {
+ length=targetCapacity;
+ }
+ while(length>0) {
+ b=*source++;
+ if(!isLegalIMAP(b)) {
+ /* illegal */
+ bytes[0]=b;
+ byteIndex=1;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ } else if(b!=AMPERSAND) {
+ /* write directly encoded character */
+ *target++=b;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ } else /* AMPERSAND */ {
+ /* switch to Unicode mode */
+ nextSourceIndex=++sourceIndex;
+ inDirectMode=FALSE;
+ byteIndex=0;
+ bits=0;
+ base64Counter=-1;
+ goto unicodeMode;
+ }
+ --length;
+ }
+ if(source=targetLimit) {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+unicodeMode:
+ /*
+ * In Unicode (or "escape") Mode, UTF-16BE is base64-encoded.
+ * The base64 sequence ends with any character that is not in the base64 alphabet.
+ * A terminating minus sign is consumed.
+ * US-ASCII must not be base64-ed.
+ *
+ * In Unicode Mode, the sourceIndex has the index to the start of the current
+ * base64 bytes, while nextSourceIndex is precisely parallel to source,
+ * keeping the index to the following byte.
+ * Note that in 2 out of 3 cases, UChars overlap within a base64 byte.
+ */
+ while(source0x7e) {
+ /* illegal - test other illegal US-ASCII values by base64Value==-3 */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ } else if((base64Value=FROM_BASE64_IMAP(b))>=0) {
+ /* collect base64 bytes into UChars */
+ switch(base64Counter) {
+ case -1: /* -1 is immediately after the & */
+ case 0:
+ bits=base64Value;
+ base64Counter=1;
+ break;
+ case 1:
+ case 3:
+ case 4:
+ case 6:
+ bits=(uint16_t)((bits<<6)|base64Value);
+ ++base64Counter;
+ break;
+ case 2:
+ c=(UChar)((bits<<4)|(base64Value>>2));
+ if(isLegalIMAP(c)) {
+ /* illegal */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ goto endloop;
+ }
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex-1;
+ }
+ bytes[0]=b; /* keep this byte in case an error occurs */
+ byteIndex=1;
+ bits=(uint16_t)(base64Value&3);
+ base64Counter=3;
+ break;
+ case 5:
+ c=(UChar)((bits<<2)|(base64Value>>4));
+ if(isLegalIMAP(c)) {
+ /* illegal */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ goto endloop;
+ }
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex-1;
+ }
+ bytes[0]=b; /* keep this byte in case an error occurs */
+ byteIndex=1;
+ bits=(uint16_t)(base64Value&15);
+ base64Counter=6;
+ break;
+ case 7:
+ c=(UChar)((bits<<6)|base64Value);
+ if(isLegalIMAP(c)) {
+ /* illegal */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ goto endloop;
+ }
+ *target++=c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ sourceIndex=nextSourceIndex;
+ }
+ byteIndex=0;
+ bits=0;
+ base64Counter=0;
+ break;
+ default:
+ /* will never occur */
+ break;
+ }
+ } else if(base64Value==-2) {
+ /* minus sign terminates the base64 sequence */
+ inDirectMode=TRUE;
+ if(base64Counter==-1) {
+ /* &- i.e. a minus immediately following an ampersand */
+ *target++=AMPERSAND;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex-1;
+ }
+ } else {
+ /* absorb the minus and leave the Unicode Mode */
+ if(bits!=0 || (base64Counter!=0 && base64Counter!=3 && base64Counter!=6)) {
+ /* bits are illegally left over, a UChar is incomplete */
+ /* base64Counter other than 0, 3, 6 means non-minimal zero-padding, also illegal */
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ }
+ sourceIndex=nextSourceIndex;
+ goto directMode;
+ } else {
+ if(base64Counter==-1) {
+ /* illegal: & immediately followed by something other than base64 or minus sign */
+ /* include the ampersand in the reported sequence */
+ --sourceIndex;
+ bytes[0]=AMPERSAND;
+ bytes[1]=b;
+ byteIndex=2;
+ }
+ /* base64Value==-1 for characters that are illegal only in Unicode mode */
+ /* base64Value==-3 for illegal characters */
+ /* illegal */
+ inDirectMode=TRUE;
+ *pErrorCode=U_ILLEGAL_CHAR_FOUND;
+ break;
+ }
+ } else {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+endloop:
+
+ /*
+ * the end of the input stream and detection of truncated input
+ * are handled by the framework, but here we must check if we are in Unicode
+ * mode and byteIndex==0 because we must end in direct mode
+ *
+ * conditions:
+ * successful
+ * in Unicode mode and byteIndex==0
+ * end of input and no truncated input
+ */
+ if( U_SUCCESS(*pErrorCode) &&
+ !inDirectMode && byteIndex==0 &&
+ pArgs->flush && source>=sourceLimit
+ ) {
+ if(base64Counter==-1) {
+ /* & at the very end of the input */
+ /* make the ampersand the reported sequence */
+ bytes[0]=AMPERSAND;
+ byteIndex=1;
+ }
+ /* else if(base64Counter!=-1) byteIndex remains 0 because there is no particular byte sequence */
+
+ inDirectMode=TRUE; /* avoid looping */
+ *pErrorCode=U_TRUNCATED_CHAR_FOUND;
+ }
+
+ /* set the converter state back into UConverter */
+ cnv->toUnicodeStatus=((uint32_t)inDirectMode<<24)|((uint32_t)((uint8_t)base64Counter)<<16)|(uint32_t)bits;
+ cnv->toULength=byteIndex;
+
+ /* write back the updated pointers */
+ pArgs->source=(const char *)source;
+ pArgs->target=target;
+ pArgs->offsets=offsets;
+ return;
+}
+
+static void
+_IMAPFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
+ UErrorCode *pErrorCode) {
+ UConverter *cnv;
+ const UChar *source, *sourceLimit;
+ uint8_t *target, *targetLimit;
+ int32_t *offsets;
+
+ int32_t length, targetCapacity, sourceIndex;
+ UChar c;
+ uint8_t b;
+
+ /* UTF-7 state */
+ uint8_t bits;
+ int8_t base64Counter;
+ UBool inDirectMode;
+
+ /* set up the local pointers */
+ cnv=pArgs->converter;
+
+ /* set up the local pointers */
+ source=pArgs->source;
+ sourceLimit=pArgs->sourceLimit;
+ target=(uint8_t *)pArgs->target;
+ targetLimit=(uint8_t *)pArgs->targetLimit;
+ offsets=pArgs->offsets;
+
+ /* get the state machine state */
+ {
+ uint32_t status=cnv->fromUnicodeStatus;
+ inDirectMode=(UBool)((status>>24)&1);
+ base64Counter=(int8_t)(status>>16);
+ bits=(uint8_t)status;
+ }
+
+ /* UTF-7 always encodes UTF-16 code units, therefore we need only a simple sourceIndex */
+ sourceIndex=0;
+
+ if(inDirectMode) {
+directMode:
+ length=(int32_t)(sourceLimit-source);
+ targetCapacity=(int32_t)(targetLimit-target);
+ if(length>targetCapacity) {
+ length=targetCapacity;
+ }
+ while(length>0) {
+ c=*source++;
+ /* encode 0x20..0x7e except '&' directly */
+ if(inSetDIMAP(c)) {
+ /* encode directly */
+ *target++=(uint8_t)c;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ } else if(c==AMPERSAND) {
+ /* output &- for & */
+ *target++=AMPERSAND;
+ if(targetcharErrorBuffer[0]=MINUS;
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ } else {
+ /* un-read this character and switch to Unicode Mode */
+ --source;
+ *target++=AMPERSAND;
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ }
+ inDirectMode=FALSE;
+ base64Counter=0;
+ goto unicodeMode;
+ }
+ --length;
+ }
+ if(source=targetLimit) {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+unicodeMode:
+ while(sourcecharErrorBuffer[0]=MINUS;
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ goto directMode;
+ } else {
+ /*
+ * base64 this character:
+ * Output 2 or 3 base64 bytes for the remaining bits of the previous character
+ * and the bits of this character, each implicitly in UTF-16BE.
+ *
+ * Here, bits is an 8-bit variable because only 6 bits need to be kept from one
+ * character to the next. The actual 2 or 4 bits are shifted to the left edge
+ * of the 6-bits field 5..0 to make the termination of the base64 sequence easier.
+ */
+ switch(base64Counter) {
+ case 0:
+ b=(uint8_t)(c>>10);
+ *target++=TO_BASE64_IMAP(b);
+ if(target>4)&0x3f);
+ *target++=TO_BASE64_IMAP(b);
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ b=(uint8_t)((c>>4)&0x3f);
+ cnv->charErrorBuffer[0]=TO_BASE64_IMAP(b);
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=(uint8_t)((c&15)<<2);
+ base64Counter=1;
+ break;
+ case 1:
+ b=(uint8_t)(bits|(c>>14));
+ *target++=TO_BASE64_IMAP(b);
+ if(target>8)&0x3f);
+ *target++=TO_BASE64_IMAP(b);
+ if(target>2)&0x3f);
+ *target++=TO_BASE64_IMAP(b);
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex;
+ *offsets++=sourceIndex++;
+ }
+ b=(uint8_t)((c>>2)&0x3f);
+ cnv->charErrorBuffer[0]=TO_BASE64_IMAP(b);
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ b=(uint8_t)((c>>8)&0x3f);
+ cnv->charErrorBuffer[0]=TO_BASE64_IMAP(b);
+ b=(uint8_t)((c>>2)&0x3f);
+ cnv->charErrorBuffer[1]=TO_BASE64_IMAP(b);
+ cnv->charErrorBufferLength=2;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=(uint8_t)((c&3)<<4);
+ base64Counter=2;
+ break;
+ case 2:
+ b=(uint8_t)(bits|(c>>12));
+ *target++=TO_BASE64_IMAP(b);
+ if(target>6)&0x3f);
+ *target++=TO_BASE64_IMAP(b);
+ if(targetcharErrorBuffer[0]=TO_BASE64_IMAP(b);
+ cnv->charErrorBufferLength=1;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+ if(offsets!=NULL) {
+ *offsets++=sourceIndex++;
+ }
+ b=(uint8_t)((c>>6)&0x3f);
+ cnv->charErrorBuffer[0]=TO_BASE64_IMAP(b);
+ b=(uint8_t)(c&0x3f);
+ cnv->charErrorBuffer[1]=TO_BASE64_IMAP(b);
+ cnv->charErrorBufferLength=2;
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ bits=0;
+ base64Counter=0;
+ break;
+ default:
+ /* will never occur */
+ break;
+ }
+ }
+ } else {
+ /* target is full */
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ break;
+ }
+ }
+ }
+
+ if(pArgs->flush && source>=sourceLimit) {
+ /* flush remaining bits to the target */
+ if(!inDirectMode) {
+ if(base64Counter!=0) {
+ if(targetcharErrorBuffer[cnv->charErrorBufferLength++]=TO_BASE64_IMAP(bits);
+ *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+ /* need to terminate with a minus */
+ if(target